Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Splitting every 3 digits?

by hopes (Friar)
on Sep 29, 2001 at 04:27 UTC ( #115551=note: print w/ replies, xml ) Need Help??

in reply to Splitting every 3 digits?

You can use 'g' modifier to the regexp, and then it could returns an array

my $a = '059057034037063107105003046039039036107063035046'; my @nums = split /(\d{3})/g,$a;

Hope this helps
Update Yes, I didn't notice it.
My first script returns empty values too because of the split.

If you want to use split, you can try:
my @nums = grep $_,split /(\d{3})/g,$a;
but is better without split
my @nums = $a=~/\d{3}/g;

Comment on Re: Splitting every 3 digits?
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Splitting every 3 digits?
by zeidrik (Scribe) on Oct 01, 2001 at 11:05 UTC
    How about this?
    my $var="1112223334445556667"; $var=~s/(\d{3})/$1\_/g; my @nums=split(/_/,$var);

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-11-29 02:53 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls