in reply to printing every 2nd entry in a list backwards
Print is slow, you can try to speed up your solution by taking it out of the loop
In hindsight you want grep not a map
updated $,=" " , haukex++
Also a common trick for a flip flop boolean state is inversion with xor $i^=1print map {$i++ & 1 ? "" : "$_ "} reverse split(/ /);
In hindsight you want grep not a map
$,=" "; print grep { $i^=1 } reverse split(/ /);
updated $,=" " , haukex++
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: printing every 2nd entry in a list backwards
by Anonymous Monk on May 19, 2017 at 14:17 UTC | |
Re^2: printing every 2nd entry in a list backwards
by Anonymous Monk on May 19, 2017 at 14:01 UTC |
In Section
Seekers of Perl Wisdom