Use the ref function.. foreach $key(keys %hash) { if(ref($hash{$key})){ print "$key = array( "; foreach my $item (@{$hash{$key}}){ print "$item "; ) print ")\n"; } else { print "$key = $hash{$key}\n"; }
} > -----Original Message----- > From: Dave Chappell [mailto:[EMAIL PROTECTED]] > Sent: Thursday, April 11, 2002 11:02 AM > To: [EMAIL PROTECTED] > Subject: Extracting values from hash keys > > > Hi, > > > > I have a hash that will have some keys contain single values > and other keys > that will have multiple values: > > > > %hash = ( > > key1 => 'test-1', > > key2 => ['test-2-0', 'test-2-1'], > > key3 => 'test-3' > > ); > > > > I want to loop through the hash getting the value(s) from > each key. When I > try this with the code below, key2 returned something different. > > > > foreach $key(keys %hash) { > > print "$key = $hash{$key}\n"; > > } > > > > screen output: > > key1 = test-1 > > key2 = ARRAY(0x1bdf0b4) > > key3 = test-3 > > > > How could I expand the foreach to also get the values from key2? > > > > Regards, > > > > Dave > > > > ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]