Assigning anonymous hash to a list
Peter Flanigan
pjf at roxsoft.co.uk
Tue Jul 30 20:15:06 BST 2013
On 30/07/13 19:54, gvim 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
>
>
Try
my ($str, $ref) = ( 'text', {a => 1, b => 2, c => 3} );
The extra set of brackets force evaluation in a list context
--
Regards
More information about the london.pm
mailing list