Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Split on every second character

by rubasov (Friar)
on Feb 13, 2010 at 10:35 UTC ( #823004=note: print w/replies, xml ) Need Help??


in reply to Split on every second character

Or still using split, you can just drop every second element from the result list:
$ perl -le '@l = grep {$i++ % 2} split /(..)/, "010203040506"; print j +oin "|", @l'
But the solutions provided by other monks are definitely nicer.

Replies are listed 'Best First'.
Re^2: Split on every second character
by AnomalousMonk (Canon) on Feb 13, 2010 at 20:26 UTC

    I agree that some variation of an approach using  m/..?/g or  unpack() is better, but a more concise  split() solution would be:

    >perl -wMstrict -le "print for grep length, split /(..)/, '0001020304101112';" 00 01 02 03 04 10 11 12

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2016-09-27 22:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (516 votes). Check out past polls.