Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: join two hashes

by JavaFan (Canon)
on Jul 30, 2011 at 10:19 UTC ( [id://917602]=note: print w/replies, xml ) Need Help??


in reply to join two hashes

"Best way"? By which measurement? I may write it as (untested code):
my %new_hash; $new_hash{$_} = [$rep{$_}, $comb{$_}] for keys %rep;
or
my %new_hash = map {($_, [$rep{$_}, $comb{$_}])} keys %rep;

Replies are listed 'Best First'.
Re^2: join two hashes
by Anonymous Monk on Jul 30, 2011 at 10:33 UTC

    in this case i have this error

     key=ARRAY<0x1889c64>
      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.
      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.

      What does that mean? Its like saying the answer to Life, the Universe, and Everything, is 42 -- does not compute

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://917602]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found