Created
February 24, 2009 17:43
-
-
Save tyru/69675 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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