Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

RE: A whirleygig for a progress indicator for scripts

by btrott (Parson)
on Mar 23, 2000 at 00:13 UTC ( [id://5913]=note: print w/replies, xml ) Need Help??


in reply to A whirleygig for a progress indicator for scripts

In that spirit, here's another idea for improving/generalizing your code.
package Whirley; sub new { my $type = shift; my $class = ref $type || $type; my $WHIRLEY_COUNT = -1; my @whirley = map chr, qw/32 176 177 178 219 178 177 176/; my $self = sub { $WHIRLEY_COUNT = 0 if ++$WHIRLEY_COUNT == @whirley; return $whirley[$WHIRLEY_COUNT]; }; bless $self, $class; } package main; my $whirley = new Whirley; while (1) { sleep 1; print STDERR "please wait: ", $whirley->(), "\r"; }
This packages up your whirley functionality into a package and a closure--you could even put it into Whirley.pm or something; then just use it and call it as illustrated.

Replies are listed 'Best First'.
Re: RE: A whirleygig for a progress indicator for scripts
by synistar (Pilgrim) on Dec 08, 2003 at 22:15 UTC

    Taking it one step further here is a repackage of btrott's version that takes an argument to choose from an array of weird spinners.

    # main my $whirley = Whirley->new(1); while (1) { sleep 1; print STDERR "please wait: ", $whirley->(), "\r"; } package Whirley; sub new { my $type = shift; my $number = shift; my $class = ref $type || $type; my $WHIRLEY_COUNT = -1; my @whirleyhash = ( [qw(- \ | / )], [map chr, qw/32 176 177 178 219 178 177 176/], [qw(>--- ->-- -->- ---> ---* --- ---< --<- -<-- <--- *---)], [qw(_o_ \o/ _O_ \O/)], [qw/. .o .oO .oO(zzz) .oO(ZZZ) /], [ '(^_^ )','( ^_^)'], [ '(^_^ )','( ^_^)','( -_-)', '(-_- )' ] ); my @whirley = @{$whirleyhash[$number]}; my $self = sub { $WHIRLEY_COUNT = 0 if ++$WHIRLEY_COUNT == @whirley; return $whirley[$WHIRLEY_COUNT]; }; bless $self, $class; }
      Is there anyway i can use Whirley with File::Copy ?

      I want to show a progress meter (percentage) while moving a file.
      I found http://www.perlmonks.org/?node=File%20copy%20progress. but that doesn't use File::Copy and dont know if it working for large files.
      Or can i do something like;

      my $sizetarget= (-s $destination); my $sizesource= (-s $source); my $percentage=""; while (move($source,$destination) || print "$!\n") { $sizetarget = (-s $destination); $percentage = ($sizetarget / $sizesource)*100; print "[$percentage\%]\r"; }
      hmm nope that doesnt work.. anyways you get my point.
      Hope anyone can give me an example or a hand :).
      greets,
      Wire64

        No. From looking at the File::Copy source code, it provides no progress callback. You could try to override CORE::sysread and/or CORE::syswrite, which File::Copy uses in its inner loop. Or just do the progress based on the number of files.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2025-06-23 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.