Skip to content

Commit

Permalink
document ref assignment in list context
Browse files Browse the repository at this point in the history
The 'refaliasing' feature, whereby assigning to a literal reference
causes an aliasing operation (e.g. \$x = \...) didn't document what was
returned if the assignment was done in list context.

This commit adds a basic summary to the docs.

See the thread http://nntp.perl.org/group/perl.perl5.porters/267074
for the discussion.
  • Loading branch information
iabyn committed Nov 16, 2023
1 parent 0fc8a78 commit 5d65e37
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pod/perlref.pod
Expand Up @@ -865,6 +865,16 @@ for obfuscated code:
my $type = ref $thingy;
($type ? $type eq 'ARRAY' ? \@foo : \$bar : $baz) = $thingy;

A reference assignment in list context returns a list of references to
each left-hand value. So for example

@b = ((\$l1, \$l2, \(@a)) = (\$r1, \$r2, $\r3, \$4));

is equivalent to

(\$l1, \$l2, \(@a)) = (\$r1, \$r2, $\r3, \$4);
@b = (\$l1, \$l2, \$a[0], \$a[1]);

The C<foreach> loop can also take a reference constructor for its loop
variable, though the syntax is limited to one of the following, with an
optional C<my>, C<state>, or C<our> after the backslash:
Expand Down

0 comments on commit 5d65e37

Please sign in to comment.