in reply to Re: Perlplexation - foreach shoulda Known
in thread Perlplexation - foreach shoulda Known
There is not. If you're reading a file $. contains the file's line number. But if you're iterating over elements in an array it may make sense in some situations to iterate over the index instead:
foreach my $idx ( 0 .. $#array ) { do_something($array[$idx]) unless $idx % 3; # Do something else that isn't filtered by iteration number. }
In your example, it's probably clearer to iterate over the list rather than the indices, but in some cases the code becomes clearer the other way.
Dave
|
---|