perlsleepparperl-packager

perl par-packer exe file sleep() not working


hello.pl is a file which works fine:

print "Hello World";
sleep(5);

When I convert that to hello.exe using par-packer, window will sleep for 5 sec but won't print "Hello World" - which is actually printed after 5 sec and window exits.

Any solution is appreciated. I want the print to be displayed for 5 sec.


Solution

  • That would be an issue of flushing the buffer to STDOUT. You can either manually flush before the sleep with

    STDOUT->flush() # a specific instance of $filehandle->flush()
    

    or you can ask that the that file handle be automatically flushed for you.

    STDOUT->autoflush(1);
    

    Also you can turn that off with a 0 as the parameter.

    Lastly there's a less readable special variable $| which you can assign 1 to if you're doing some kind of one-liner or code-golfing.