Skip to content

Commit 16cc56d

Browse files
committed
More on list variables with my and our.
See issue #1958
1 parent 4cff385 commit 16cc56d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

doc/Language/variables.pod6

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ say $foo; # Exception! "Variable '$foo' is not declared"
477477
This dies because C<$foo> is only defined as long as we are in the same
478478
scope.
479479
480+
In order to lexically scope more than one variable at the same time, surround
481+
the variables with parentheses:
482+
483+
my ( $foo, $bar );
484+
485+
see also L<Declaring a list of variables lexically or package scoped|/variables#list_of_variables_my_our>.
486+
480487
Additionally, lexical scoping means that variables can be temporarily
481488
redefined in a new scope:
482489
@@ -529,12 +536,21 @@ introduce an alias into the symbol table.
529536
530537
# Available as $M::Var here.
531538
539+
In order to package scope more than one variable at the same time, surround
540+
the variables with parentheses:
541+
542+
our ( $foo, $bar );
543+
544+
see also L<Declaring a list of variables lexically or package scoped|/variables#list_of_variables_my_our>.
545+
546+
547+
X<list_of_variables_my_our|Declaring a list of variables lexically (C<my>) or package (C<our>) scoped>
532548
=head2 Declaring a list of variables lexically (C<my>) or package (C<our>) scoped
533549
534550
It is possible to scope more than one variable at a time, but both C<my>
535551
and C<our> require variables to be placed into parentheses:
536552
537-
my (@a, $s, %h); # same as my @a; my $s; my %h;
553+
my (@a, $s, %h); # same as my @a; my $s; my %h;
538554
our (@aa, $ss, %hh); # same as our @aa; our $ss; our %hh;
539555
540556
This can be used in conjunction with X«destructuring assignment». Any

0 commit comments

Comments
 (0)