C
Cathy
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 I'm sorry if this is too easy question.
I wanted to indicate the progress of line number while reading a file.
In a source code above, it prints out total line number first, and
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?
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 I'm sorry if this is too easy question.
I wanted to indicate the progress of line number while reading a file.
In a source code above, it prints out total line number first, and
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?