CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
"Warn" prints faster than "print"? Race conditions question

 



run414
New User

Mar 4, 2009, 10:34 AM

Post #1 of 4 (571 views)
"Warn" prints faster than "print"? Race conditions question Can't Post

I'm having some problems with race conditions in my program, as warn and print are not guaranteed to print in the order they are called.

For example, consider the part of my program shown below

Code
if(do pattern matching stuff) 
{
print "Now looking at document titled $1)
}

if(do more pattern matching stuff)
{
warn "This document contains terrible, terrible things\n";
}


The output is always:

Quote
This document contains terrible, terrible things
Now looking at document titled Bob


This is really annoying. Does anybody have any suggestions to force the warn and print to finish in the correct order?


FishMonger
Veteran / Moderator

Mar 4, 2009, 10:45 AM

Post #2 of 4 (569 views)
Re: [run414] "Warn" prints faster than "print"? Race conditions question [In reply to] Can't Post


Code
$| = 1; 

if(do pattern matching stuff)
{
print "Now looking at document titled $1)
}

if(do more pattern matching stuff)
{
warn "This document contains terrible, terrible things\n";
}



run414
New User

Mar 4, 2009, 11:01 AM

Post #3 of 4 (567 views)
Re: [FishMonger] "Warn" prints faster than "print"? Race conditions question [In reply to] Can't Post

Hey, that worked. I haven't heard of the $| variable before. What does it do?

Nevermind. I found an explanation here: http://www.bjnet.edu.cn/tech/book/perl/ch17.htm#BufferingOutputTTFONTSIZEFONTTT


(This post was edited by run414 on Mar 4, 2009, 11:09 AM)


FishMonger
Veteran / Moderator

Mar 4, 2009, 11:11 AM

Post #4 of 4 (563 views)
Re: [run414] "Warn" prints faster than "print"? Race conditions question [In reply to] Can't Post

autoflush HANDLE EXPR
$OUTPUT_AUTOFLUSH
$|

http://www.perl.com/doc/manual/html/pod/perlvar.html

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives