Kevin Old wrote:
Hello everyone,
Hello,
I have a line like the following:
my $line = "31232000 07/28/04 DUC000 NET 60 DAYS RD 222264
UPSGNDSVR PREPAID";
What I'm looking for in lines like this are the customer number
(DUC000) and a "code" that starts with UPS, or if the code doesn't
start with UPS idealy I'd like to have whatever was in that place
returned, but I can't figure that out and can settle for just nothing
returned along with the customer number.
The problem with the regex below is that if the shipping "code"
doesn't start with UPS, it doesn't return the custnum.
$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(UPS\w+)\s/;
$custnum = $1;
$isups = $2;
I know I'm missing something basic. I've even tried grouping it and
trying the zero or more matching:
$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(?:(UPS\w+)\s)*/
This doesn't match anything.
It looks like you have fixed length fields so you may want to use unpack.
my ( $custnum, $isups ) = unpack 'x18 A7 x37 A12', $line;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>