in reply to Subroutine for showing the end user the progress of the program

I have once have written my own little Module for that purpose. I donīt know if it works on Unix (if not please tell me), but for Windows it works fine.
Other than a progressbar it is capable to display a rotating line, a widening/narrowing line or rotating brackets.
That is especially useful when you donīt know the amount of work before it is done.
package Progress; use strict; our $VERSION = '0.02'; sub new { my $classname = shift; my %attr = @_; my $self = bless \%attr, $classname; $self->{style} = 'simple' unless defined $self->{style}; $self->{styles} = { simple => ["-", "\\", "|", "/"], bracket => ["]", ")", "|", "(", "[", "(", "|", ")"], line => [" ", " - ", " --- ", "-----", " --- ", " - + "], }; if ( defined $self->{freestyles} && ref ( $self->{freestyles} ) eq + "ARRAY" ) { $self->{styles}->{"free"} = $self->{freestyles}; $self->{style} = 'free'; } $self->reset; return $self; } sub reset { my $self = shift; print chr(8) x $self->{last_char_length}; print " " x $self->{last_char_length}; print chr(8) x $self->{last_char_length}; $self->{_chars} = $self->{styles}->{$self->{style}}; } sub next { print STDOUT ""; $|=1; my $self=shift; print chr(8) x ($self->{last_char_length} ); my $char = shift @{ $self->{_chars} }; push @{ $self->{_chars} }, $char; $self->{last_char_length} = length ($char); print $char; }
Use it as follows:
use Progress; my $p = Progress->new(style=>"line"); # or # my $p = Progress->new(style=>"bracket"); # or # my $p = Progress->new(style=>"simple"); # or (equiv. to simple) # my $p = Progress->new(); # or # my $p = Progress->new( style=>"free", freestyles => [("a".."z")]); for ($i=0;$i<10;$i++) { $p->next(); sleep(1); } $p->reset();
Update:
To "install" this, simply copy & paste the first code-block and save it as "Progress.pm" to the perl-library path (most probably "perl/lib").

holli, regexed monk

Replies are listed 'Best First'.
Re^2: Subroutine for showing the end user the progress of the program
by ghenry (Vicar) on Feb 02, 2005 at 15:16 UTC

    I don't knwo how to install a non-CPAN module?

    I only know perl -MCPAN -e shell

    Just getting into the best language ever... Fancy a yourname@perl.me.uk? Just ask!!!