Home > Archive > PERL Beginners > February 2006 > elsif not working
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| LeeAnn 2006-02-22, 3:55 am |
| I have a script that reads through a file and writes out to 2 files
(OUT and OUTWALM)depending on a value in one of the first records.
For some reason a piece of my script is ALWAYS screwing up no matter
what I do.
The part is...
} elsif (/^HEADER /) {
my @fields = split(/~/, $_);
my $header = $fields[1];
my $edi_asn_id = $fields[2];
my $create_date = $fields[3];
my $create_time = $fields[4];
if ($walflag="NO") {
print OUT join('~', @fields, "\n");
print ARCH join('~', @fields, "\n");
print STDOUT join('~', @fields, "\n");
print STDOUT ($walflag);
}
if ($walflag="YES") {
print OUTWALM join('~', @fields, "\n");
print ARCH join('~', @fields, "\n");
print STDOUT join('~', @fields, "\n");
print STDOUT ($walflag);
}
The program will output this "Header" line twice, regardless of what
the flag walflag is set at, and it will CHANGE the value of the flag to
the opposite! I have other parts in the script that are exactly like
this, just looking for different values other than "HEADER".
If I remove this part the rest of the program works with no problem.
ANY SUGGESTIONS???
I am a beginner at this, so be kind.
| |
|
| LeeAnn wrote:
> I have a script that reads through a file and writes out to 2 files
> (OUT and OUTWALM)depending on a value in one of the first records.
> For some reason a piece of my script is ALWAYS screwing up no matter
> what I do.
>
> The part is...
> } elsif (/^HEADER /) {
> my @fields = split(/~/, $_);
> my $header = $fields[1];
> my $edi_asn_id = $fields[2];
> my $create_date = $fields[3];
> my $create_time = $fields[4];
> if ($walflag="NO") {
NOT comparing ! It is asignment !!
> print OUT join('~', @fields, "\n");
> print ARCH join('~', @fields, "\n");
> print STDOUT join('~', @fields, "\n");
> print STDOUT ($walflag);
> }
> if ($walflag="YES") {
Second time !!
> print OUTWALM join('~', @fields, "\n");
> print ARCH join('~', @fields, "\n");
> print STDOUT join('~', @fields, "\n");
> print STDOUT ($walflag);
> }
> The program will output this "Header" line twice, regardless of what
> the flag walflag is set at, and it will CHANGE the value of the flag to
> the opposite! I have other parts in the script that are exactly like
> this, just looking for different values other than "HEADER".
>
> If I remove this part the rest of the program works with no problem.
> ANY SUGGESTIONS???
> I am a beginner at this, so be kind.
| |
|
|
MSG wrote:[color=darkred]
> LeeAnn wrote:
> NOT comparing ! It is asignment !!
>
> Second time !!
>
Also in Perl, Numerical comparision uses different operator from
that of string.
== for numberical. eq for string...
perldoc perlop
| |
| LeeAnn 2006-02-22, 6:56 pm |
| oh my!!! I have stared at this program for 36 hours and did not see
that! I have "eq" everywhere else but there!
THANK YOU!
|
|
|
|
|