for (0
.. $#foo) {
if ($foo[$_] =~/corge/) {
$bar{$_} = $foo[$_];
}
}
Simple enough. But consider that if you're reading through a filehandle, you can use $. (or $INPUT_LINE_NUMBER) to tell you how many lines you've read. It'd be very handy to have another special variable - let's call it $¬ because there are hardly any symbols left - that, if you're in a loop, gives you the number of times it has run. That way you could replace the code above with:
foreach (@foo) {
if (/corge/) {
$bar{$¬} = $_;
}
}
This immediately strikes me as Perlish.
Addendum: Well, it would, if use.perl's code formatter didn't buggily replace ¬ with ¬ in the code snippet above. I hope you can still see what I mean.
each @array in 5.12 (Score:2)
5.12 will support
eachon arrays. So that would be:You can have this right now with Aaron Crane's Array::Each::Override [cpan.org].
Re: (Score:1)
Re: (Score:1)
rjbs