in reply to looping through array references
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;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: looping through array references
by johngg (Canon) on Feb 04, 2008 at 00:08 UTC |