in reply to grep { } positional number of element
grep only goes through the actual elements of whatever is passed to it. No index is passed. You might want something like–
my @myArray = qw(alfa beta gamma); grep { print "$myArray[$_] at $_\n" } 0 .. $#myArray;
But that is *atrocious* style. grep is for filtering, not iterating. Use a for loop instead. Terse postfix version, you should generally prefer the expanded with a block–
print "$myArray[$_] at $_\n" for 0 .. $#myArray;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep { } positional number of element
by Fletch (Bishop) on Oct 24, 2022 at 02:12 UTC |