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

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?

Replies are listed 'Best First'.
Re^4: Error: Odd number of elements in anonymous hash
by Marshall (Canon) on Jul 23, 2011 at 07:43 UTC
    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" }
Re^4: Error: Odd number of elements in anonymous hash
by Anonymous Monk on Jul 23, 2011 at 07:17 UTC
    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 };