>>> Peter Guzis <[EMAIL PROTECTED]> 02/27/01 05:10PM >>>
This *should* work, but I haven't tested it out thoroughly.  Be sure to
specify a length of time to sleep or it will wait forever.

##

if ('some condition' eq 'true') {

} elsif ($line =~ m/^PO1<<\d+<EA<(.+)<<UP<(\d{12})<?V?A?<?(\w+)?.+/) {

        $upc = $2;
        $desc = $3;

} elsif ($line =~ m/(^CTP<<RES<)(.+)<\d+<EA.+\n/) {

        $price = $2;

} elsif (my ($sdq) = $line =~ m/^SDQ<EA<92<(.+)$/) {

        my @sdq = split /</, $sdq;

        for my $idx (0..$#sdq) {

                if ($idx % 2) { # odd

                        printf CUSTORD1 "%d,%s,%s,%d\n", $sdq[$idx], $upc,
$price, $sdq[$idx + 1] if $sdq[$idx];

                } else { # even

                        $sdq[$idx] = 3 if $sdq[$idx] > 3 && $limit{$desc};

                }

        }

        warn "UPC number $upc doesn't exist in the Elite database!!!!!\n" if
length($upc_itemlist{$upc}) == 0;
        sleep  if length($upc_itemlist{$upc}) == 0;

}

##

Out of curiosity, what application outputs this type of datafile?

Peter Guzis
Web Administrator, Sr.
ENCAD, Inc.
email: [EMAIL PROTECTED] 
www.encad.com 

-----Original Message-----
From: Greg Wardawy [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, February 27, 2001 10:07 AM
To: [EMAIL PROTECTED] 
Subject: Repeated pattern matching

Hello all,

To extract data from the following text:

-snip-

The SDQ line can have up to 10 pairs store/quantity ($sdq+odd
number/$sdq+even number) and, as you can see, my pattern matching is really
ugly - any solutions

are greatly appreciated. I think this is a good way to learn a good style of
programming - do something yourself, even if it's ugly, then ask gurus how
it should be in proper programming style. And the next question: how can I
avoid repetition of the print statement above? 

TIA



Greg.

And many thanks for all of you again. I'm going to write a new script right now.
Peter, my input file is a raw datafile which I'm receiving during the EDI 
transmission. Unfortunately, there are no Perl EDI modules and I'm  not yet able to 
write
them. Thanks a lot, guys.

Greg
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED] 
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to