If you are on a system that supports zenity - it is yet another option. It uses a real progress bar which may not be what you want (will only work on your local machine). Here is a very long one liner that makes the use of most zenity progress options (you could shorten it to zenity --progress --pulsate):
perl -e 'open my $fh, "|-", q{zenity --title=Working --width=400 --pro
+gress --text="Still going..." --percentage=50 --no-cancel --auto-kill
+ --auto-close}; select $fh; $|=1; select(undef,undef,undef,.1),print
+$fh "$_\n#Now on $_...\n" for 1..100'
Here is the code broken out into more of a program.
use IO::Handle; # for older perls
use Time::HiRes qw(usleep);
my $pid = open my $fh, "|-", q{zenity --title=Working --width=400 --pr
+ogress --percentage=50 --no-cancel --auto-kill --auto-close}
or die "Could not open zenity: $!";
$fh->autoflush(1);
for my $i (1 .. 100) {
usleep 100_000; # microseconds
print $fh "$i\n"; # move the bar
print $fh "#Now on $i...\n"; # update the text
print "We've done $i\n";
if ($i >= 50) {
#kill 2 $pid; # not as portable
print $fh "100\n"; # more portable with --auto-kill
last;
}
}
my @a=qw(random brilliant braindead); print $a[rand(@a)];
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.