3
3
> "1st law of language redesign: Everyone wants the colon for their particular syntax.
4
4
> 2nd law of language redesign: Larry gets the colon for whatever he wants."
5
5
6
- Basics doesn 't mean here not always easy but rather fundamental.
6
+ Basics don 't always mean easy, but fundamental.
7
7
8
8
Defaults
9
9
========
@@ -19,45 +19,64 @@ or [**class**](appendix-a-index.html#class). That marks your code as Perl 6
19
19
(in case the interpreter defaults to Perl 5) and makes it possible to mix
20
20
Perl 5 and 6 in one source file.
21
21
22
- To even that little obstacle, you can leave out the usual `use strict;` and
23
- `use warnings;` in front of every script, because that is now the default.
24
- Also `use utf8;` is obsolete since any Perl 6 source code is always treated
25
- as UTF-8 and any [*unicode*](appendix-g-glossary.html#unicode) character can
26
- be used anywhere in the code. Even the features of the pragmas `constant` and
27
- `vars` are now part of the core language.
22
+ Where you had to include `use strict;` and `use warnings;` at the top
23
+ of every perl5 script, it's now default in perl6. Also `use utf8;` is
24
+ obsolete since any Perl 6 source code is always treated as UTF-8 and
25
+ any [*unicode*](appendix-g-glossary.html#unicode) character can be used
26
+ anywhere in the code. Even pragmas such as `constants` and `vars` are
27
+ now part of the core language.
28
28
29
29
Also the functionality of many useful and famous modules like Moose
30
30
(object system), Parse::RecDescent++, exception handling,
31
- List::\[More\]Utils, Export, English an advanced pretty printer and
32
- much more is already built in. So you get a lot extra for a little **v6;**.
33
-
31
+ List::\[More\]Utils, Export, English, an advanced pretty printer and
32
+ much more is already built in. So you get a lot extra for a little
33
+ **v6;**.
34
34
35
35
36
36
Statements
37
37
==========
38
38
39
- Unless you use [*blocks*](appendix-g-glossary.html#block), a Perl program
40
- executes one statement after another in linear progression (from left to right,
41
- from up to down). They have to be separated by a
42
- semicolon ([ **;**](appendix-a-index.html#semicolon-terminator)),
43
- except before and after a closing curly brace, where it is optional, always .
39
+ Unless you use [*blocks*](appendix-g-glossary.html#block), a Perl
40
+ program executes one statement after another in linear progression
41
+ ( from left to right, top down). They have to be separated by
42
+ a semicolon (**;**), except before and after a closing curly brace,
43
+ where it is optional.
44
44
45
45
$coderef = sub { fetch_data(); compute() }
46
46
47
47
48
48
Spaces and Indentation
49
49
======================
50
50
51
- Perl doesn't care about indentation. Otherwise, in several place Perl 6 cares
52
- about existence of whitespace as a disambiguator.
51
+ Perl doesn't care about indentation, but it does care about whitespace
52
+ as a disambiguator. For example, `$foo$bar` is a syntax error since that
53
+ has two terms in a row without any whitespace to tell them apart. There's
54
+ a new addition in perl6, the so called "unspace" operator. It is basically
55
+ an instruction to the compiler's lexer that it should ignore whitespace there.
56
+ In other words, the lexer doesn't consider those whitespaces at all.
57
+
58
+ my %hash = "foo" => 42, "bar" => 84;
59
+ say %hash \{"foo"}; # Same as saying %hash{"foo"}
60
+
61
+ my $clazz = new Camel;
62
+ $clazz\#some random comment
63
+ .drink(); # same as saying $clazz.drink();
64
+
65
+ #or even
66
+ $clazz\#`{some random multiline
67
+ comment`}.drink(); # which brings us to the next section...
68
+
69
+
70
+
71
+
72
+ ...$var []
53
73
54
74
...$var []
55
75
56
76
Comments
57
77
========
58
78
59
79
60
-
61
80
Single Line
62
81
-----------
63
82
@@ -140,7 +159,7 @@ An extended delimiter mechanism is delivered by [heredocs](#heredocs).
140
159
Interpolation
141
160
-------------
142
161
143
- Inside of these delimiters, every character will be taken
162
+ Within these delimiters, every character will be taken
144
163
literally. Any additional meaning has to be added by [quoting
145
164
adverbs](appendix-b-grouped.html#quoting-adverbs) that have to
146
165
follow the Q. Most of them have a short and a long name and some of
@@ -154,12 +173,12 @@ altogether with the Q operator (like single or double quotes).
154
173
:c aka :closure # anonymous blocks: {...}
155
174
:f aka :function # callable routines: &name(...)
156
175
157
- For more info on those, see [scalar
158
- variable](ap-b-lookup.html#scalar), [array
159
- variable](ap-b-lookup.html#array), [hash
160
- variable](ap-b-lookup.html#hash), [anonymous
161
- blocks](tablet-6-blocks.html), and [callable
162
- routines](tablet-3-variables.html#callable).
176
+ For more info on those, see
177
+ * [scalar variable](ap-b-lookup.html#scalar),
178
+ * [array variable](ap-b-lookup.html#array),
179
+ * [hash variable](ap-b-lookup.html#hash),
180
+ * [anonymous blocks](tablet-6-blocks.html), and
181
+ * [callable routines](tablet-3-variables.html#callable).
163
182
164
183
Q :b /\t\n/; # tab and new line character
165
184
Q :s /$poem/; # content of $poem
@@ -200,10 +219,11 @@ following are synonyms:
200
219
'...'
201
220
202
221
203
- The backslash (\\) here is only required to delimite itself and
204
- the single quote from its special meaning. Or to put it simply \\\\
205
- translates (or interpolates) to \\ and \\' to '. For anything more
206
- you need additional adverbs.
222
+ We sometimes use the backslash (\\) to escape other special characters
223
+ or the backslash itself. These are all part of the family of characters
224
+ known as /escape sequences/. For example, `\\\\` translates to `\\`, while
225
+ `\\'` translates to a `'`. You can avoid all that extra typing by using
226
+ adverbs.
207
227
208
228
'Welcome in Larry\'s madhouse'
209
229
'\'\\'; # string contains: '\
@@ -248,7 +268,7 @@ The second group of aliases mark a modified version, where single and
248
268
double quoted strings (inside the quote) are treated as one
249
269
word. This is called *quote* protection.
250
270
251
- my @steps = <one "two three">; # 3 steps to success: ["one", "\"two", "three\""]
271
+ my @steps = <one "two three">; # 3 steps to success: ["one", "\"two", "three\""]
252
272
my @steps = <<one "two three">>; # now only 2 steps: ["one", "two three"]
253
273
254
274
0 commit comments