Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
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 imbibing at the Monastery: (5)
As of 2014-12-21 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls