in reply to Perl Bug?
Please take the time and reduce your code to the bare minimum. The problem was completely unrelated to ps -ef, it was completely unrelated to the actual platform, it was completely unrelated to the weird inclusion of other scripts you did.
The problem can be reduced to the following code:
use strict; my $PLATFORM = 'solaris'; foreach($PLATFORM) { (/solaris/ || /tru64/ || /linux/ || /aix/) and do { my $i=1; print "\$PLATFORM is '$PLATFORM'\n"; open (PSTEST, $0); while (<PSTEST>){ print "Line # ".$i."\n".$_; print "Platform now is '$PLATFORM'\n"; $i++; }; print "All done!\n"; close PSTEST; print "Platform now is '$PLATFORM'\n"; }; };
Please note the somewhat more instructive debugging output. Your problem stems from the spurious foreach ($PLATFORM) loop, which sets $_ as an alias to $PLATFORM and then clobbers it in the while loop. You can circumvent the problem by removing the spurious foreach loop which will execute only once anyway.
use strict; my $PLATFORM = 'solaris'; #foreach($PLATFORM) { $_ = $PLATFORM; (/solaris/ || /tru64/ || /linux/ || /aix/) and do { my $i=1; print "\$PLATFORM is '$PLATFORM'\n"; open (PSTEST, $0); while (<PSTEST>){ print "Line # ".$i."\n".$_; print "Platform now is '$PLATFORM'\n"; $i++; }; print "All done!\n"; close PSTEST; print "Platform now is '$PLATFORM'\n"; }; #};
You should really really really rewrite the code as it is an optical mess and many of the code and employed techniques are quite bizarre.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Bug?
by Knom (Beadle) on Nov 22, 2005 at 11:29 UTC | |
by Corion (Patriarch) on Nov 22, 2005 at 12:13 UTC | |
by Knom (Beadle) on Nov 23, 2005 at 01:05 UTC |