in reply to Need sleep walking help
something change if put $|++; at the top of your code? I suspect yes.
Infact you are not printing newlines and the console is linebuffered. Instead of $|++; you can also modify 'print "$I "; ' into 'print "$I\n"; ' to get the expected output.
Look at these example and how the output come out:
perl -e "sleep 1 and print qq($_ ) for 1..$ARGV[0]" 3 1 2 3 perl -e "$|++; sleep 1 and print qq($_ ) for 1..$ARGV[0]" 3 1 2 3
I suggest you to read suffering from buffering? a milestone read and also Perl Idioms Explained - $|++
Anyway you can do something simpler like:
sub my_sleep { # no prototype my $Seconds = shift; print "Sleeping for $Seconds seconds ...\n"; # added newline sleep 1 and print "$_\n" for 1..$Seconds; print "done\n"; }
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need sleep walking help
by Todd Chester (Scribe) on Feb 01, 2017 at 08:18 UTC | |
by Discipulus (Canon) on Feb 01, 2017 at 08:22 UTC | |
by Todd Chester (Scribe) on Feb 01, 2017 at 08:31 UTC | |
by Discipulus (Canon) on Feb 01, 2017 at 08:51 UTC | |
by Marshall (Canon) on Feb 02, 2017 at 04:22 UTC | |
by Anonymous Monk on Feb 02, 2017 at 07:23 UTC | |
by haukex (Archbishop) on Feb 02, 2017 at 08:50 UTC | |
by Marshall (Canon) on Feb 02, 2017 at 08:47 UTC | |
|