bug in perl

R

robin

print "Sleep\n"; #string with newline
sleep 1;

print "Sleep"; #string without newline
sleep 1;

# in the first example, everything is fine and dandy.
#
# in the second example perl appears to be sleeping before executing
the second print command to print "sleep" without the newline.

#is this a bug in perl or something I'm just missing?


#robin
#[email protected]
 
S

Sherm Pendley

robin said:
print "Sleep\n"; #string with newline
sleep 1;

print "Sleep"; #string without newline
sleep 1;

# in the first example, everything is fine and dandy.
#
# in the second example perl appears to be sleeping before executing
the second print command to print "sleep" without the newline.

Try it in a debugger, you can easily see that's not what's happening.
#is this a bug in perl or something I'm just missing?

It's something you're missing. Perl's output is buffered - that is, output
is stored into a buffer until the buffer is flushed. By default, the buffer
is flushed whenever a newline is inserted into the output stream, so the
effect is to send a full line of output at a time.

You can enable auto-flushing, so the output buffer is automatically flushed
after each output statement. Have a look at the description of the $| variable
in "perldoc perlvar".

sherm--
 
T

Tintin

robin said:
print "Sleep\n"; #string with newline
sleep 1;

print "Sleep"; #string without newline
sleep 1;

# in the first example, everything is fine and dandy.
#
# in the second example perl appears to be sleeping before executing
the second print command to print "sleep" without the newline.

#is this a bug in perl or something I'm just missing?

My GOD!! Looks like you stumbled onto the most serious and dangerous Perl
bug ever!!!

Then again....have you considered the very real possibility that you could
actually be missing something?

perldoc -q buffer
 
J

Jürgen Exner

robin said:
print "Sleep\n"; #string with newline
sleep 1;

print "Sleep"; #string without newline
sleep 1;

# in the first example, everything is fine and dandy.
#
# in the second example perl appears to be sleeping before executing
the second print command to print "sleep" without the newline.

#is this a bug in perl or something I'm just missing?

Your Question is Asked Frequently, please see "perldoc -q buffer".

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top