Looping through Perl data types
hash
% perldoc -f keys
% perldoc -f each
If you just want the keys and do not plan to ever read any of the values, use keys():
foreach my $key (keys %hash) { ... }
If you just want the values, use values():
foreach my $val (values %hash) { ... }
If you need the keys and the values, use each():
keys %hash; # reset the internal iterator so a prior each() doesn't affect the loop
while(my($k, $v) = each %hash) { ... }
From JR's : articles
89 words - 557 chars
created on
- #
source
- versions
Related articles
Perl try, catch, eval, die, warn, carp - Jun 25, 2013
Scaup web publishing app update as of Feb 21, 2015 - Mar 02, 2015
Loop through a Perl array - Oct 02, 2013
Perl Critic and Diag - Oct 09, 2013
Perl links to read - Jul 09, 2013
more >>