coldy has asked for the wisdom of the Perl Monks concerning the following question:

Simple question, I am trying to monitor the progress of my script. I have a variable that is incremented in a loop and I would like to print its value every time it is a multiple of 100 say. Any ideas? Many thanks

Replies are listed 'Best First'.
Re: print multiple of 100
by moritz (Cardinal) on Jul 14, 2008 at 12:11 UTC
    print $variable, "\n" if $variable % 100 == 0

    Or even shorter: say $variable unless $variable % 100;

    (Note that say requires perl 5.10.0 and use 5.010; or use feature qw(say);).

    Note that if you want to print out the variable without a newline at the end, you'll have to set $| to a true value for it to display immediately.

    (Update: fixed markup, jethro++)

Re: print multiple of 100
by olus (Curate) on Jul 14, 2008 at 12:14 UTC

    do something like

    if ( ($variable_incremented % 100) == 0) { print "$variable_incremented"; }
Re: print multiple of 100
by CountZero (Bishop) on Jul 14, 2008 at 15:20 UTC
    Smart::Comments may do just what you are looking for.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James