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.
In reply to Re: Perl Bug?
by Corion
in thread Perl Bug?
by Knom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |