in reply to Interesting Use for "state" Variables
Doesn't look any cleaner thanforeach (@array) { do_something_with($item, state i++); }
(imo)my $i; foreach (@array) { do_something_with($item, $i++); }
And since 'state' is something I rarely use (ok never) you can bet I'll be looking it up in the docs every time I see it to be sure of exactly what it's doing. It's sometimes annoying that there's no magic variable to get an index in a foreach, but I think you've sacrificed readability (and portability) for the sake of a single line of convenience?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interesting Use for "state" Variables
by Lawliet (Curate) on Mar 10, 2009 at 20:46 UTC |