in reply to percentage while loop

Here's a "traditional" sort of counter, with a '.' for every percentage point and numbers at every 10% mark:

#!/usr/bin/perl -w use strict; $|++; open Fh, "file" or die "file: $!\n"; my $s = -s Fh; my ($last, $total) = 0; while (<Fh>){ $total += length; my $p = int($total * 100 / $s); if ($p != $last){ $last = $p; print STDERR $p % 10 ? "." : "$p%"; } }

-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells

Replies are listed 'Best First'.
Re^2: percentage while loop
by marto9 (Beadle) on Jul 29, 2008 at 20:32 UTC
    Thx, you helped me a lot. It works now.