in reply to Interesting Use for "state" Variables
All you need is another pair of curlies. And it will actually work correctly, unlike the state variables.
{ my $i; foreach (@array) { do_something_with($item, $i++); }}
BTW, you should NOT use
what if the $color contains some format specifiers?!? Please useprintf " %2d. '$color'\n", $idx;
instead.printf " %2d. '%s'\n", $idx, $color;
|
|---|