Bill in Brooklyn has asked for the wisdom of the Perl Monks concerning the following question:

Ok,

So I've got a real simple script that takes a list of hosts, pings them (Net::Ping), checks to make sure we have at least X number of active machines (if we don't, something is severly wrong), and then does something else. For the record, this is ActivePerl 5.8.3 on a Wintel box.

So the code, like I said, is simple (summary below):

print "Doing some work ..."; &doSomWork(); print "Done\n"; print "Doing some ping ..."; &doSomePing(); print "Done\n"; print "Checking threshold ..."; if ($yadayadaya < $yodolodolo) { die "Horrible death"; } Print "Done\n";
That's it in a nutshell. Now check out the output and notice where the "Checking threshold" line actually comes in:
C:\temp>myScript.pl Doing some work --> Done. Doing some ping --> Done. Doing something else --> Done. Number of machines to be LAPC'd (178) below threshhold (700), please i +nvestigate ! at I:\perl\lapc.pl line 41. Checking Threshold --> C:\temp>
The script does what it's supposed to and works fine, but I've noticed this before in other scripts and it seems like either a buffer isn't flushing or perl is just flatout deciding to rebel against the humans and work the code in it's own order.

Bill in Brooklyn

Replies are listed 'Best First'.
Re: print command buffer
by Bill in Brooklyn (Initiate) on Jan 25, 2005 at 22:01 UTC
    Ignore me .. I suck. I've hit 3 search engines looking for this problem and after posting about it, did a search here on PM and found the answer ($|++;).

    Like I said, ignore me.

    Bill in Brooklyn

Re: print command buffer
by trammell (Priest) on Jan 25, 2005 at 22:53 UTC
    Or you can use warn(), which goes to STDERR, and is unbuffered.