in reply to Re^3: join two hashes
in thread join two hashes

your code in my script is as follow:

my %new_hash = map {($_, [$rep{$_}, $comb{$_}])} keys %rep; for my $key(keys %new_hash){ print "$key=$new_hash{$key}\n";}

and for each key has an error like that i mentioned.

Replies are listed 'Best First'.
Re^5: join two hashes
by johngg (Canon) on Jul 30, 2011 at 11:54 UTC

    That's not an an error, that's what each value of the hash holds; a scalar reference to an anonymous array. Consider:-

    knoppix@Microknoppix:~$ perl -E ' > %rep = ( one => 123, two => 456 ); > %comb = ( one => 987, two => 654 ); > %new = map { $_, [ $rep{ $_ }, $comb{ $_ } ] } keys %rep; > say qq{$_ => $new{ $_ } => @{ $new{ $_ } }} for keys %new;' one => ARRAY(0x81a1530) => 123 987 two => ARRAY(0x8195d00) => 456 654 knoppix@Microknoppix:~$

    You have to de-reference the array reference (@{ $new{ $_ } } see perlreftut) to get at the contents.

    Update: Added documentation reference.

    Cheers,

    JohnGG

Re^5: join two hashes
by JavaFan (Canon) on Jul 30, 2011 at 15:54 UTC
    The only error is on your side. You have a hash, whose values are arrayreferences, as specified. You are printing those references - which means they are stringified. What you are seeing is the stringification of the arrayref.

    There is no bug.