#################################### ## FUNCTION: StatusBar ############### ################################################## ## ## ## Generates a statusbar that is of variable ## ## width, and is very adaptable, optionally ## ## displaying the percentage as well. ## ## ## ## ARGS: ## ## 0) The text preceeding the bar ## ## 1) The current value ## ## 2) The maximum value ## ## 3) The size of the bar (in characters) ## ## 4) Display the percentage? ## ## 5) The text following the bar ## ## Returns: ## ## NULL ## ## ## ################################################## sub StatusBar { my $level; my $numdots; my $numblanks; my $pre=$_[0]; my $cur=int($_[1]); my $max=int($_[2]); my $size=int($_[3]); my $disp=$_[4]; my $i; my $post=$_[5]; $level = $cur/$max; $numdots = int($level * $size); $numblanks = $size - $numdots; print $pre . "\t"; print " ["; for($i = 0; $i < $numdots; $i++) { print "."; } for($i = 0; $i < $numblanks; $i++) { print " "; } print "]"; if($disp ne "") { printf(" ($cur/$max, %3.2f%%)", (int($level*10000)/100)); } print " $post\r"; }

Edited 2002-01-16 to fix html entities dvergin


In reply to Doom-Style Status Bar by Symuc

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.