in reply to Re: Error: Odd number of elements in anonymous hash
in thread Error: Odd number of elements in anonymous hash

It's odd, but %$subargs is valid there. It expands the hash reference, then overwrites the values of subkey1 and subkey2.

Replies are listed 'Best First'.
Re^3: Error: Odd number of elements in anonymous hash
by onelesd (Pilgrim) on Jul 23, 2011 at 07:12 UTC
    Hmm, auto expansion of the hash reference makes sense, but why would it overwrite subkey1 and subkey2? Can you point me to some documentation regarding that?
      Its what you would expect when hash element assignment is done more than once. After expansion, args are processed left to right. The last one "wins".
      #!/usr/bin/perl -w use strict; use Data::Dump qw(pp); my $subargs = {a=>1, b=>2, subkey1 => 3}; my $r = { %$subargs, subkey1 => 'subval1', subkey2 => 'subval2'}; pp $r; #prints: #{ a => 1, b => 2, subkey1 => "subval1", subkey2 => "subval2" }
      Probably perlintro/perlsyn/perldata...
      #!/usr/bin/perl -- use strict; use warnings; my %foo = ( 1, 2 , 1, 3, 1, 3, 1, 2 ); my %bar = ( %foo, 1, 3 ); use Data::Dumper; print Dumper( \%foo, \%bar ); __END__ $VAR1 = { '1' => 2 }; $VAR2 = { '1' => 3 };