in reply to printing every 2nd entry in a list backwards
Another way:
my @x = (1, 22, 3, -4 ); print join " ", grep { state $i; $i++ % 2 == 0 } reverse @x;
The documentation advises against using map purely for its side effects. If you're not going to use the resulting list, use a for loop instead, or in the case of simply filtering a list down to a smaller list, grep.
As far as performant, I don't think you can tell much about the performance of the loop when you are opening and closing a file and only processing one line with four elements: the I/O will eat up most of the time no matter the solution.
Hope this helps!
update: show with grep
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: printing every 2nd entry in a list backwards
by Anonymous Monk on May 19, 2017 at 12:57 UTC | |
by shmem (Chancellor) on May 19, 2017 at 22:31 UTC |