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

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

I often run scripts that have to run for a while and that do not output anything. So I like to see how they are doing, if they are just sitting there waiting for something to happen, or maybe stuck in an infinite loop.

So I use this subroutine to display an indicator of how many times I have been through my main loop on STDOUT.

Its used this way:

    { # whatever you have to do

As I use in various situations the main loop can be run any time from a few hundred to several tens of thousand times, so you can pass a parameter or change the DEFAULT_STEP constant to display a dot for every n loops. After 10 dots a space is printed, and after 50 a new line (those values can also be changed).

One last thing: if you want to see the dots displayed as soon as they are generated don't forget to unbuffer the output, for example with $|=1;

Oh and if the features of this progress indicator are not what you are looking for, here is a list of previous nodes on that subject:

{ use constant DEFAULT_STEP => 100; # a DOT is printed every DEFAULT_S +TEP call use constant LINE => 50; # nb of DOT per line use constant BLOCK => 10; # a SPACE is printed after BLOCK D +OTs use constant DOT => '.'; # probably no need to change this use constant SPACE => ' '; # probably no need to change this my( $i, $j); sub progress { my $step= shift || DEFAULT_STEP; $i++; if( $i == $step) { $i=0; print STDOUT DOT; $j++; unless( $j % BLOCK) { print STDOUT SPACE; if( $j == LINE) { $j=0; print STDOUT "\n"; } } } } }

In reply to Progress indicator by mirod

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.