Re: seeking golfing advice
Ronald J Kimball <[email protected]> Wed, 16 May 2012 11:22:27 -0400
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
On Wed, May 16, 2012 at 04:40:40AM -0700, John Douglas Porter wrote: > And of course, use grep, as others have said. > > @list[ grep !$_%2, 0..$#list ]; > > that gets you every other element, beginning with the first. ! has higher precedence than %, so this actually gets you just the first element. You need to add parentheses to get the correct result: @list[grep!($_%2),0..$#list]; There are a couple ways to shave a character from that: @list[grep$_%2-1,0..$#list]; @list[grep$_+1&1,0..$#list]; Ronald