perlidiot has asked for the wisdom of the Perl Monks concerning the following question:
In the script below, the variable $fline prints expected data before the if statement $x=-/go/ but not after (it seems that the 'if then' statement erases the $fline variable).
I can simply delete the if statement that contains $x=-/go/ then the $fline variable is then ok and unchanged and prints the expected data in both print statements. In fact, several different 'tests' (such as index) instead of the if statement cause the same problem.
What the heck is the problem with this screwy perl language???? Perl is driving me crazy!!! Why does putting in some type of 'if then' statement erase a variable???? Am I just an idiot???? Am I not seeing something obvious???? How do I stop it????
#!/usr/local/bin/perl -w print "Content-type:text/html\n\n"; #Content Header open(TOP, "first.htm"); # Open db for reading and display @farray=<TOP>; close (TOP); open(BOTTOM, "second.htm"); # Open db for reading and display @sarray=<BOTTOM>; close (BOTTOM); foreach $sline(@sarray){ chomp($sline); print "second $sline \n"; if (index ($sline, "pattern") > "-1") { foreach $fline(@farray){ chomp($fline); print "first $fline \n"; if ($fline =- /go/) {print "hello";} print "first $fline \n"; } } }
Edited by footpad, ~ Mon Aug 26 02:11:50 2002 (UTC) : Added <CODE> and other HTML formatting tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable Data Lost
by elusion (Curate) on Aug 26, 2002 at 02:15 UTC | |
|
Re: Variable Data Lost
by BrowserUk (Patriarch) on Aug 26, 2002 at 02:24 UTC | |
|
Re: Variable Data Lost
by Cody Pendant (Prior) on Aug 26, 2002 at 02:48 UTC | |
by elusion (Curate) on Aug 26, 2002 at 02:54 UTC | |
by Cody Pendant (Prior) on Aug 26, 2002 at 02:58 UTC | |
by elusion (Curate) on Aug 26, 2002 at 03:05 UTC |