The basic usage is to call a subroutine, once every loop, through your long process. Like:
#!/usr/bin/perl use strict; use warnings; my $spinner_pos = 0; sub spin { my $spinner = '|\-/'; print STDERR substr($spinner, $spinner_pos++%length($spinner), 1)."\r" +; } while (1) { qx(cat /etc/termcap); #simulate doing important stuff spin(); }
So you have to design your application, and progress indicator together. There is no 1 "foolproof way" to use them. So what type of proram are you running? If you show us, we can help you with placing an indicator somewhere in the code. It's "fun" and educational to experiment yourself. Take the snippets you've received here, and play with them. You can't break anything. You will get the idea of how they work eventually.

In some "event driven programs" like Tk, you can make your indicator an object, and just do things like

$progressindicator->start; $progressindicator->stop;

here is another widely used style of indicator used by wget

#!/usr/bin/perl $|=1; do{ print progress_bar( $_, 100, 25, '=' ); sleep 1 } for 1..100; sub progress_bar { my ( $got, $total, $width, $char ) = @_; $width ||= 25; $char ||= '='; $num_width = length $total; sprintf "|%-${width}s| Got %${num_width}s bytes of %s (%.2f%)\r", $char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/$ +total; }

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

In reply to Re^3: Subroutine for showing the end user the progress of the program by zentara
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.