Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Progress Bar in Perl script

by zentara (Archbishop)
on Jul 08, 2012 at 10:54 UTC ( [id://980573]=note: print w/replies, xml ) Need Help??


in reply to Progress Bar in Perl script

A spinner in a thread is your best bet.
#!/usr/bin/perl use strict; use threads qw[ yield ]; use threads::shared; # by chanio of perlmonks # This alternative should print a line only if it succeeds # in what is doing as job. That way, there is a real # significance of the spinning wheel (sort of:). When the # job is not succeeding, the wheel should stay calm (panic!). my $ready : shared = 0; my $isOk : shared = 0; async { local $| = 1; while ( !$ready ) { do { select undef, undef, undef, 0.2; printf "\r ($_)" if ($isOk); } for qw[ / - \ | * ]; } print "\rReady"; $ready = 0; } ->detach; # do your work here for ( 1 .. 10 ) { ## Busy, busy, busy $isOk = 1; sleep 1; $isOk = 0; } $isOk = 0; $ready = 1; yield while $ready;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Progress Bar in Perl script
by slayedbylucifer (Scribe) on Jul 09, 2012 at 08:01 UTC
    Hi, thanks for your time. But honestly, i did not understand the thread stuff. May be this is more intended for Developers.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found