[Chicago-talk] appending hashes

Jay Strauss me at heyjay.com
Sun Nov 2 18:39:27 CST 2003


Ah, 

Thanks, I knew there was a simpler way

Jay
----- Original Message ----- 
From: "Andy Lester" <andy at petdance.com>
To: "Chicago.pm chatter" <chicago-talk at mail.pm.org>
Sent: Sunday, November 02, 2003 6:32 PM
Subject: Re: [Chicago-talk] appending hashes


> > Is there any shortcut (like a slice or something) to push on hash onto
> > another:
> >
> > my %h = (a=>1, b=>2, c=>3);
> > my %a = (d=>4, e=>5);
> 
> %h = (%h,%a);
> 
> That turns %h into a list, and %a into a list, and constructs a new 
> hash in %h.  Any keys in %h that exist in %a will be overwritten.
> 
> This is a common trick to handle parms passed into arrays, especially 
> defaults:
> 
> sub foo {
> my %defaults = (
> name => "",
> x => 0,
> y => 0,
> );
> 
> my %parms = ( %defaults, @_ );
> }
> 
> xoa
> 
> --
> Andy Lester
> andy at petdance.com, AIM:petdance
> http://petdance.com/ http://use.perl.org/~petdance/
> 
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
> 
> 




More information about the Chicago-talk mailing list