Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Progress Bar in Perl script

by Rhandom (Curate)
on Jul 10, 2012 at 14:36 UTC ( #980880=note: print w/ replies, xml ) Need Help??


in reply to Progress Bar in Perl script

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)];


Comment on Re: Progress Bar in Perl script
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980880]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-12-29 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls