in reply to A string parsing question

** IGNORE **

Or..

my $data = 'NCC045-071-109-SCC021-087-091-011545-'; $data =~ s/([A-Z]+)//; my $state = $1; my @counties = split('-', $data); print join(' ', map { $state.$_; } @counties), "\n";
Runs, and will handle any number of codes on the same line.

Replies are listed 'Best First'.
Re: Re: A string parsing question
by suaveant (Parson) on Apr 20, 2001 at 19:29 UTC
    Ahhh, but it only catches the first state code... the 4th item becomes NCCSCC021, does it not? And the expiry date has NCC prepended, too...
                    - Ant
      Thanks for pointing that out. I was never too good at those reading comprehension thingies.
Re: Re: A string parsing question
by Sifmole (Chaplain) on Apr 20, 2001 at 19:29 UTC
    ** Ignore... this is wrong **

    Another alternative if you don't like the map and split.

    my $data = 'NCC045-071-109-SCC021-087-091-011545-'; $data =~ s/([A-Z]+)//; my $state = $1; print $state, $1, ' ' while ($data =~ m/(\d+)/g);