develooper Front page | perl.perl5.porters | Postings from February 2016

[perl #127531] permit \escape on right hand side of my

Thread Previous
From:
Ricardo SIGNES
Date:
February 13, 2016 03:03
Subject:
[perl #127531] permit \escape on right hand side of my
Message ID:
rt-4.0.18-28961-1455332602-1396.127531-75-0@perl.org
# New Ticket Created by  Ricardo SIGNES 
# Please include the string:  [perl #127531]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127531 >


This is pretty useful:

  perl -Mexperimental=refaliasing \
       -E 'my $x = [1,2,3]; \my @y = $x; say for @y'

...but the question I keep hearing is "why is the backslash on the my and not
the variable?"

The answer is not weird.  It's pre-existing syntax to get a reference to a new
variable.  It's still confusing, though, because people expect to be able to
write:

  my \@y = $x;

I even got this question from Larry.

We should allow that.  It would also be good to allow:

  my ($x, \@y, \%z) = @_;

...which means we should then allow:

  sub foo ($x, \@y, \%z) { ... }

I would use the *heck* out of that feature.

-- 
rjbs

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About