Skip to content

Instantly share code, notes, and snippets.

@tyru
Created February 24, 2009 17:43
Show Gist options
  • Select an option

  • Save tyru/69675 to your computer and use it in GitHub Desktop.

Select an option

Save tyru/69675 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use IO::Handle;
use Time::HiRes qw(sleep);
for my $i (1 .. 100) {
sleep 0.02;
my $msg = "counting...$i/100";
progress_print($msg);
}
for my $i (reverse 1 .. 100) {
sleep 0.02;
my $msg = "counting...1/$i";
progress_print($msg);
}
print "\n\n";
{
my $prev_msg_len;
BEGIN { $prev_msg_len = 0 }
sub progress_print {
my $msg = shift;
# delete previous message.
print ' ' x $prev_msg_len;
$prev_msg_len = length $msg;
# print message.
print "\r$msg";
STDOUT->flush;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment