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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.