http://qs321.pair.com?node_id=11140919


in reply to Re: The print is output later after die
in thread The print is output later after die

*STDOUT->autoflush;

My goto answer would have been $|++.
I'm thinking it's a case of "six of one; half-a-dozen of the other".
Is there a difference ?

Cheers,
Rob

Replies are listed 'Best First'.
Re^3: The print is output later after die
by ikegami (Patriarch) on Jan 28, 2022 at 12:21 UTC

    $| = 1; affects the currently selected handle. This is the handle print, printf and say use if you don't provide one., and it defaults to STDOUT.

    In fact, ->autoflush changes the currently selected handle to the invocant, sets $|, then restores the originally selected handle.

Re^3: The print is output later after die
by Discipulus (Canon) on Jan 28, 2022 at 12:05 UTC
    Hello syphilis,

    differences? perlvar says that $|++ flush right away and after every write or print on the currently selected output channel while *STDOUT->autoflush only affect STDOUT your example instead any select -ed FH and so also STDERR in case of warn or die

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^3: The print is output later after die
by choroba (Cardinal) on Jan 28, 2022 at 12:05 UTC
    See IO::Handle. There's no difference, just readability :-)

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      There's a difference. $| = 1; is equivalent to select()->autoflush(), not STDOUT->autoflush().