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

In reply to Re: Subroutine for showing the end user the progress of the program by holli
in thread Subroutine for showing the end user the progress of the program by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.