Sorry so lengthy but here goes:

I am a Perl newbie and trying to parse a file.  Depending on the tags in the
data I want to parse each line a different way.  I built the following
program to test my process. 

use strict;
my (@lines, $testln, @REFln);

while (<>) {
        chomp;
        testType ($_);
}

sub testType {
        $testln = $_[0];
        if (/^REF/) {
                print "I found a REF line: $testln\n";
                parseRef ($testln);
        } elsif (/^NTE/) {
                print "I found a NTE line: $testln\n";
        }
}

sub parseREF {
        print "Parsing line: $_[0]\n";
        
        @REFln = split (/\*/, $_[0]);
        
        print "Element 1) $REFln[0] ";
        print " 2) $REFln[1] ";
        print " 3) $REFln[2]\n";
        
        if ($REFln[1] = "SN") {
                print "$REFln[1]: $REFln[2]\n";
        } else {
                print "Not a Shipment Number, $REFln[1] type line.\n";
        }
}

Based on the input:
CUR**USD
REF*SN*0108106
REF*PO*cn190108106
REF*BL*cn190108106
REF*PS*JessupPA

I expected to see "SN: 0108106" (which I did) but I didn't expect to see
"SN: cn190108106" and "SN: cn190108106", "SN: JessupPA".  
I expected to see "Not a Shipment Number, PO/BL/PS  type line." for those.  
It almost seems like $REFln[1] is not being refreshed each time parseREF
happens.

I have written this same program in VB but I'm trying to do my parsing in
Perl now .  To tell you the truth I really don't have a clue why this
doesn't work, so any help is much appreciated.

Joel

Reply via email to