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

You mean, if you run my code, the error you get is key=ARRAY<0x1889c64>? That would be quite strange, as that's not a standard Perl error. And the code snippet I gave doesn't do any I/O by itself.

Replies are listed 'Best First'.
Re^4: join two hashes
by Anonymous Monk on Jul 30, 2011 at 11:09 UTC

    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.

      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

      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.