my $lines = 0;
my $current_line = 0;
my $percentage;
my $percentage_new;

open(my $FILE,  "<",  @ARGV[0])  or die "Can't open log file: $!";

while (sysread $FILE, $buffer, 4096) {
        $lines += ($buffer =~ tr/\n//);
}

print "$lines lines\n";
close $FILE or die "$in: $!";

open(my $FILE,  "<",  @ARGV[0])  or die "Can't open log file: $!";

while(<$FILE>) {
        $current_line += 1;
        $percentage_new = sprintf("%d",$current_line / $lines * 100);

        #$delta = $percentage_new - $percentage;
        #print "$delta\n";
        if($percentage_new - $percentage > 0) {
                print "$current_line\n";
                $percentage = $percentage_new;
        }
}

Hi all,
This is my first post and this could be easy question.

In a source code above, it prints out total line number first, and in
a loop ,
it prints out the line number whenever the percentage increases.
The problem is, when I put \r instead of \n, nothing is printed.
But if I remove 'if' statement, it prints out normally with \r.
Does anyone know what is wrong?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to