Assigning anonymous hash to a list
Adrian Lai
perl at loathe.me.uk
Tue Jul 30 20:23:30 BST 2013
my ($a, $b) = 'x', 'y';
say $b; # undef
my ($a, $b) = ('x', 'y');
say $b; # y
I assume Perl interprets as (my ($a, $b) = 'x'), 'y'.
Adrian.
On 30 July 2013 19:54, gvim <gvimrc at gmail.com> wrote:
> Can anyone explain why this works:
>
> my $ref = {a => 1, b => 2, c => 3};
> say $ref->{b}; # Result: 2
>
> ... but this doesn't :
>
> my ($str, $ref) = 'text', {a => 1, b => 2, c => 3};
> say $ref->{b}; # Result: Use of uninitialized value
>
> Seems a little inconsistent.
>
> gvim
>
More information about the london.pm
mailing list