Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How to join 2 Hash's into one?

Quote Reply
How to join 2 Hash's into one?
 
if I've got 2 hash...

$hash1
$hash2

how can I join them so all variables are in one like..

$hash3


thanks
regan.
Quote Reply
Re: [ryel01] How to join 2 Hash's into one? In reply to
I'd like to know this too Smile

You can do a dirty hack with something like;

Code:
$hash_1 = ; # defined earlier
$hash_2 = ; # defined earlier

$hash_1->{YourField} = $hash_2->{YourField}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How to join 2 Hash's into one? In reply to
thanks andy - there's no way to assign "all" values over easily is there? maybe a for or while loop... (I can't remember how to do it it's been too long since I put my mind to programming!). Blush

r
Quote Reply
Re: [ryel01] How to join 2 Hash's into one? In reply to
$hashref3 = {%$hashref1, %$hashref2};

Keys in both hashref1 and hashref2 will end up with hashref2's value in hashref3 - reverse the order of $hashref1, $hashref2 if you want the opposite behaviour.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] How to join 2 Hash's into one? In reply to
thanks jason!

that's what I was after exactly! overwriting the values too.

never knew you could do it that way.

cheers!

Regan.
Quote Reply
Re: [Jagerman] How to join 2 Hash's into one? In reply to
In Reply To:
$hashref3 = {%$hashref1, %$hashref2};

Keys in both hashref1 and hashref2 will end up with hashref2's value in hashref3 - reverse the order of $hashref1, $hashref2 if you want the opposite behaviour.

Thanks Cool

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How to join 2 Hash's into one? In reply to
Hey Andy - it's pretty good huh!

FYI - I've just been working with it and you can list as many hash's as you like to allocate to the new hash - each will override the one to the left of it.

$NEWhash = { %$hash1, %$hash2, %$hash4, %$hash4...} ;

r
Quote Reply
Re: [ryel01] How to join 2 Hash's into one? In reply to
Quote:
Hey Andy - it's pretty good huh!

FYI - I've just been working with it and you can list as many hash's as you like to allocate to the new hash - each will override the one to the left of it.

$NEWhash = { %$hash1, %$hash2, %$hash4, %$hash4...} ;

Sweet Cool This is something I've wanted to do for ages, but never really had the need to do it (thus havn't bothered learning).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!