in reply to printing a running count

$| = 1; # it's important for autoflush to be on my $counter; for ( $counter = 0; $counter < 5000; $counter++ ) { # ... # check, is this the 5th object? if ( ( $counter % 5 ) == 0 ) { printf( "%5d\r", $counter ); } } # clear status print( ( " " x 5 ) . "\n" );

Using the mod (or %) operator takes the remainder after dividing the given number. So, in this case, taking the remainder after dividing $counter by five is what we want. When the remainder is zero we have every 5th object.

Printing a number with the \r code instructs the terminal to move the cursor to the beginning of the line without overwriting or going to a new line.