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

in this case i have this error

 key=ARRAY<0x1889c64>

Replies are listed 'Best First'.
Re^3: join two hashes
by choroba (Cardinal) on Jul 30, 2011 at 10:49 UTC
    It is not an error. The value of the key is the array reference as you wanted (or at least we can guess so, because a comma is missing in your spec). See perlref.
Re^3: join two hashes
by JavaFan (Canon) on Jul 30, 2011 at 11:00 UTC
    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.

      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.

Re^3: join two hashes
by Anonymous Monk on Jul 30, 2011 at 10:37 UTC
    What does that mean? Its like saying the answer to Life, the Universe, and Everything, is 42 -- does not compute