The only time the foreach makes more sense (other than as a matter of preference) is if you want to sort your keys or values.
e.g. foreach(sort keys %hash){ print "$_ => $hash{$_}\n"; } foreach(sort {$hash{$a} cmp $hash{$b}} keys(%hash)){ print "$_ => $hash{$_}\n"; } -----Original Message----- From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 08, 2003 4:32 PM To: Johnstone, Colin Cc: '[EMAIL PROTECTED]' Subject: Re: Looping through a Hash Sort of.... foreach my $key (keys(%picDetails)) { my $val = $picDetails{$key}; # do stuff to val } or while (my ($key, $val) = each (%picDetails)) { # do stuff to key or val } (foreach may work here as well, but I have always preferred while's for some reason) perldoc -f each perldoc -f keys perldoc -f values http://danconia.org Johnstone, Colin wrote: > Gidday All, > > Can I do this when looping through a Hash. > > foreach my($k, $v)( %picDetails ){ > do stuff to $v; > } > > Thanking you in Anticipation > > Colin > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]