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
Veery Blog App - April 2015 - Aug 03, 2015
Perl code for string processing - Jul 06, 2013
Run perl script as a daemon - Nov 14, 2014
Quotes in Perl - Oct 12, 2013
Perl Timer Code - Feb 11, 2015
more >>