Hi Joel,

Did you type this in by hand? :) 

>               parseRef ($testln);
> sub parseREF {

You would want to change one of those! Anyways..

Your problem is in this line:

>       if ($REFln[1] = "SN") {

= is for assignments. You want this to be:

        if ($REFln[1] eq "SN") {

To learn more about perl operators like eq, =, and == (which is for numeric
comparisons, while eq is for strings) read the perlop manual page.

Cheers,
Kevin

On Tue, Apr 24, 2001 at 08:20:59PM -0000, Stout, Joel R ([EMAIL PROTECTED]) 
spew-ed forth:
> 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
> 

Writing CGI Applications with Perl - http://perlcgi-book.com
-- 
Nuclear explosions under the Nevada desert? What the f*ck are we testing for?
We already know the sh*t blows up.
        -- Frank Zappa

Reply via email to