SPUG: RE / Split Question

John Subaykan cansubaykan at hotmail.com
Wed Jul 30 19:44:44 CDT 2003


if you know that you always have 3 digits, space, 3 digits, or even some 
digits, space, some digits:

You can use a while loop (here is one possible way):

my @array;

while ($scalar =~ /((?:\b\d+\s+)+.+?)(?=$|\b\d)/g) {
    push @array, $1;
}


you can use split:

my @array2 = split /\s(?=\d+ \d+)/, $scalar;




----Original Message Follows----

Hello All,

Please help with the following dilemma:

      I am being given a glob of data from a web page that I need to fix
with perl.  It comes in as $blob looking like this:

425 501 sttlwa01t 425 712 sttlwa01t tacwa02t 425 337 tacwa02t ...

I need to break this up so the word characters associated with the
numbers stay with their numbers.  Ideally, I would have an array like
this:

425 501 sttlwa01t
425 712 sttlwa01t tacwa02t
425 337 tacwa02t

As you can see, I am not assured of the number of words that will follow
each set of numbers.  Could you please suggest a split or some other
tool that will turn the glob into the fix?
$new_array = [ split /(?=[A-Z]\s\d)/,$scalar ];

Which is as close as we got, does not work.  It keeps the split
characters, but in a funky way that I cannot deal with.  It also will
always miss the last chunk of the glob.


Thanks,
Chuck
_____________________________________________________________
Seattle Perl Users Group Mailing List
POST TO: spug-list at mail.pm.org   Wiki: spugwiki.perlocity.org
ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays, U-District, Seattle WA
WEB PAGE: www.seattleperl.org

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail




More information about the spug-list mailing list