I use the following because it limits the scope of the two variables, $item and $hash_ref, to the loop where they are used.
It also continues to work when you add extra code that includes a next or redo statement.for my $item ( 0 .. $#{$ref} ) { $hash_ref = $ref->[$item]; print "$hash_ref->{'key1'}; }
Update fixed code thanks to johngg. Teach me to post without running it first;)
In reply to Re: looping through array references
by hipowls
in thread looping through array references
by cosmicperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |