Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: merging two hashes

by ikegami (Pope)
on Feb 08, 2006 at 20:53 UTC ( #528930=note: print w/ replies, xml ) Need Help??


in reply to merging two hashes

While [ ... ] constructs an array, it returns a reference to the array, not the array itself. That means that $s->{aa}->{'1'} (for example) is a reference to an array. You need to dereference it.

my @a = ( @{$s->{aa}->{'1'}}, @{$s->{bb}->{'1'}}, @{$s->{cc}->{'1'}}, );

or (minimal change)

my @a = map { @$_ } ( $s->{aa}->{'1'}, $s->{bb}->{'1'}, $s->{cc}->{'1'}, );

or

my @a = map { @{$s->{$_}->{'1'}} } keys %$s;


Comment on Re: merging two hashes
Select or Download Code
Replies are listed 'Best First'.
Re^2: merging two hashes
by Roy Johnson (Monsignor) on Feb 08, 2006 at 22:20 UTC
    If you're not going to sort the keys, you can just use values
    my @a = map @{$_->{1}}, values %$s;

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2015-07-29 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls