Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Split on every second character

by linuxer (Curate)
on Feb 12, 2010 at 23:00 UTC ( [id://822949]=note: print w/replies, xml ) Need Help??


in reply to Split on every second character

If you are sure that the string is even sized, you can use a simple regex like this:

use strict; use warnings; my $string = "0102030405"; # will miss the last character when string is odd sized my @elements = $string =~ m/(..)/g; print "@elements\n";
Update: modified code

Replies are listed 'Best First'.
Re^2: Split on every second character
by GrandFather (Saint) on Feb 12, 2010 at 23:05 UTC

    and if you are unsure but want the last character for odd length strings you can:

    my @list = $str =~ /(..?)/g;

    True laziness is hard work
Re^2: Split on every second character
by gri6507 (Deacon) on Feb 12, 2010 at 23:12 UTC
    I didn't think of using the match operator for this. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found