Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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
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


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

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-31 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls