You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/variables.pod6
+14-9Lines changed: 14 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ Examples:
50
50
my %hash = London => 'UK', Berlin => 'Germany';
51
51
52
52
X<|is (type of variable)>
53
-
The type to which the variable will be bound, can be set with C<is> in the
53
+
The type to which the variable will be bound can be set with C<is> in the
54
54
declaration of the variable. Assuming we have a C<FailHash> class:
55
55
56
56
class FailHash is Hash {
@@ -68,7 +68,7 @@ declaration of the variable. Assuming we have a C<FailHash> class:
68
68
One can then define a C<%h> variable using C<is>:
69
69
70
70
=forcode :preamble<class FailHash {}>
71
-
my %h is FailHash = oranges => "round", bananas => "bendy";
71
+
my %h is FailHash = oranges => "round", bananas => "bendy";
72
72
73
73
And then run the following code:
74
74
@@ -139,12 +139,17 @@ assignment expression is parsed as C<@array = (($num = 42), "str")>, because
139
139
item assignment has tighter precedence than the comma. However, let's see what
140
140
happens if the internal variable assignment is in a list context:
141
141
142
-
my ( @foo, $bar );
143
-
@foo = ($bar) = 42, "str"; # list assignment for $bar: uses parentheses
144
-
say @foo.perl; # OUTPUT: «[(42, "str"),]» (an Array)
145
-
say $bar.perl; # OUTPUT: «$(42, "str")» (a List)#
142
+
=forcode
143
+
my ( @foo, $bar );
144
+
@foo = ($bar) = 42, "str"; # list assignment for $bar: uses parentheses
145
+
say @foo.perl; # OUTPUT: «[(42, "str"),]» (an Array)
146
+
say $bar.perl; # OUTPUT: «$(42, "str")» (a List)#
146
147
147
-
In this case, C<()> is the list contextualizer, putting the assignment to C<$bar> in a list context; C<$bar> then I<decides> to include all the items to the right hand side of the C<=> sign; this is still included in a list assignment to C<@foo>, which then becomes an array with a single element, a C<List>.
148
+
In this case, C<()> is the list contextualizer, putting the assignment to
149
+
C<$bar> in a list context; C<$bar> then I<decides> to include all the items to
150
+
the right hand side of the C<=> sign; this is still included in a list
151
+
assignment to C<@foo>, which then becomes an array with a single element, a
152
+
C<List>.
148
153
149
154
See L<operators|/language/operators> for more details on precedence.
150
155
@@ -166,8 +171,8 @@ you've defined it:
166
171
θ = 3; # Dies with the error "Cannot modify an immutable Num"
167
172
=endcode
168
173
169
-
Sigilless variables do not enforce context, so they can be used to pass
170
-
something on as-is:
174
+
Sigilless variables do not enforce L<context|/language/contexts>, so they can be
0 commit comments