Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Mini-Tutorial: Working with Odd/Even Elements

by spazm (Monk)
on Jul 09, 2009 at 18:46 UTC ( [id://778657]=note: print w/replies, xml ) Need Help??


in reply to Mini-Tutorial: Working with Odd/Even Elements

my $t = 0; grep { $t^=1 } LIST
using the XOR operator in XOR-equal is bordering on line-noise. This seems to have a low likely hood of being understood on the first pass by the next person to see it. (This next person had to go check perlop). That said, I'm totally using it the next time I play golf.

Mixing both of your two forms we get these nice options:

my $t = 0; #even elements #my $t= 1; #odd elements grep { $t++ % 2 } LIST
my $t = 0; map { $t++ %2 ? $_ : () } LIST
Am I wrong to expect people to be more familiar with '%' than with '^'?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://778657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found