[Chicago-talk] appending hashes

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Mon Nov 3 10:22:40 CST 2003

my %h = (a=>1, b=>2, c=>3);
my %a = (d=>4, e=>5);

%h = (%h, %a);
for my $key ( keys %h ) {
  print "Key: $key: $h{$key}\n"

A hash is just (sort of) a list of key value pairs, so making one big 
array/list of it ...  the '=>' Supercomma is just a comma that 
automatically quotes the lhs, i.e
my %a = ('a', 1, ...);
is the same as:
my %a = (a => 1, ...)

%h = (%h, %a);
just unrolls the hashs and rolls them all back up again.

You'd think there'd be a way to push (%a) on to the end of %h w/o 
unrolling %h (what if its really big or something?) but, besides the map 
sort of method, I can't think of a way.


Andy Bach, Sys. Mangler
Internet: andy_bach at wiwb.uscourts.gov 
VOICE: (608) 261-5738  FAX 264-5030

 "I'm not sure what LInux-friendly means" 
Martin Taylor, MicroSoft's Linux strategist

More information about the Chicago-talk mailing list