bug in perl

Discussion in 'Perl Misc' started by robin, Sep 26, 2005.

  1. robin

    robin Guest

    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
    #
     
    robin, Sep 26, 2005
    #1
    1. Advertising

  2. "robin" <> writes:

    > 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--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Sep 26, 2005
    #2
    1. Advertising

  3. robin

    Tintin Guest

    "robin" <> wrote in message
    news:...
    > 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
     
    Tintin, Sep 26, 2005
    #3
  4. robin wrote:
    > 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
     
    Jürgen Exner, Sep 26, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,868
  2. Xah Lee
    Replies:
    14
    Views:
    988
    Michele Dondi
    Jan 27, 2004
  3. Xah Lee
    Replies:
    13
    Views:
    219
    Michele Dondi
    Jan 27, 2004
  4. Xah Lee
    Replies:
    14
    Views:
    225
    Michele Dondi
    Jan 27, 2004
  5. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    335
    PerlFAQ Server
    Jan 23, 2011
Loading...

Share This Page