Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: join two hashes

by koolgirl (Hermit)
on Jul 30, 2011 at 21:50 UTC ( [id://917651]=note: print w/replies, xml ) Need Help??


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

Thanks, that cleared up a few things for me..I was quite perplexed at the thought of creating key-value pairs, with multiple values, (of course, once there's more than two, it would no longer be a technical "pair"). I mean not only does the entire concept make my brain hurt, but I thought the idea of multiple values per key sort of defeated the purpose of creating a hash altogether (not to mention the idea of how to get to each individual value and the complications arising from that).

Thinking of it along the lines as each key still only having "one" value, that "one" value being a reference to other lists (or, arrays, rather)/hashes, makes a little more sense to me, but, ultimately, still hurts my brain...oO

Replies are listed 'Best First'.
Re^3: join two hashes
by johngg (Canon) on Jul 31, 2011 at 02:05 UTC

    One way to ease the brain ache is to use Data::Dumper to visualise your data structures.

    knoppix@Microknoppix:~$ perl -MData::Dumper -Mstrict -wE ' > my %rep = ( one => 123, two => 456 ); > my %comb = ( one => 987, two => 654 ); > my %new = map { $_, [ $rep{ $_ }, $comb{ $_ } ] } keys %rep; > print Data::Dumper->Dumpxs( > [ \ %rep, \ %comb, \ %new ], > [ qw{ *rep *comb *new } ] > ); > say q{-} x 30; > push @{ $new{ two } }, 888; > $new{ three } = { four => 444, five => 555 }; > print Data::Dumper->Dumpxs( [ \ %new ], [ qw{ *new } ] );' %rep = ( 'one' => 123, 'two' => 456 ); %comb = ( 'one' => 987, 'two' => 654 ); %new = ( 'one' => [ 123, 987 ], 'two' => [ 456, 654 ] ); ------------------------------ %new = ( 'three' => { 'five' => 555, 'four' => 444 }, 'one' => [ 123, 987 ], 'two' => [ 456, 654, 888 ] ); knoppix@Microknoppix:~$

    I hope this is helpful.

    Cheers,

    JohnGG

      It does, actually, works just like tylenol! I'm actually trying to learn how to work with modules at the moment, because I really haven't been doing much of that at all and I know I'm limiting my growth by not, so this is a great starting point for me to begin working with one on a specific point of interest. Thanks :D

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2024-03-28 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found