in reply to Trying to make a simple countdown timer

I will guess that you are getting no output at all until the program ends and everything appears at once?

Try inserting $| = 1; at line 4 and consult perlvar for what that means. :-)

Replies are listed 'Best First'.
Re^2: Trying to make a simple countdown timer
by maxamillionk (Acolyte) on Aug 29, 2020 at 00:12 UTC
    Ok good I think I overlooked how the printing to STDOUT is buffered by default, thanks for that. Problem solved. But I would only want the change of $| to 1 to affect that function, and when it exits I want $| back to default. Would this do that?
    sub countdown { local $| = 1; my $int = $_[0]; while ($int > 0) { print "$int ... "; sleep 1; $int--; } print "\n"; }
    *edit* just tried and seems to work as expected.