Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Splitting every 3 digits?

by hopes (Friar)
on Sep 29, 2001 at 04:27 UTC ( [id://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
Hopes
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;
Regards

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://115551]
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-20 01:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found