Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Anonymous Monk
on Jul 09, 2009 at 18:44 UTC ( #778654=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 '^'?

Replies are listed 'Best First'.
Re^2: Mini-Tutorial: Working with Odd/Even Elements
by eyepopslikeamosquito (Chancellor) on Jul 10, 2009 at 07:40 UTC

    my $t = 0; grep { $t^=1 } LIST
    ... That said, I'm totally using it the next time I play golf.
    No. In golf, the --$| magical flip-flop is shorter. For example:
    grep--$|,LIST

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://778654]
help
Chatterbox?
[LanX]: ... understood everything after mentally write down what he said.
[choroba]: Trainspotting?
[choroba]: Ouch, trailing commas in JSON :-(
[LanX]: ... though there seems to exist a taxation for the letter 't' in Northern Bri''ain ;-)
[LanX]: never seen trainspotting in OV ... :(
[karlgoethebier]: LanX
[LanX]: They should teach Scottish in continental schools after Brexit !!!

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2018-02-19 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (261 votes). Check out past polls.

    Notices?