Assigning anonymous hash to a list

Abigail abigail at abigail.be
Tue Jul 30 20:51:20 BST 2013


On Tue, Jul 30, 2013 at 07:54:46PM +0100, 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.


You could have asked Perl....

  $ perl -we 'my ($str, $ref) = "text", {a => 1, b => 2, c => 3}'
  Useless use of anonymous hash ({}) in void context at -e line 1.
  $


Abigail


More information about the london.pm mailing list