Commit e58cbd07 authored by Nigel Kukard's avatar Nigel Kukard

Support for progress indicator on loading files

parent f6786b4a
......@@ -194,31 +194,32 @@ sub loadFile
}
# Open file
if (!open(FH,"<",$parms->{'file'})) {
my $FH;
if (!open($FH,"<",$parms->{'file'})) {
print($OUT " => Failed to open '".$parms->{'file'}."': $!\n");
return -1;
}
# Process lines
printf($OUT " => Loading file '%s'",$parms->{'file'});
printf($OUT " => Loading file '%s'\n",$parms->{'file'});
# Grab number of lines to process
my $line_total = 0;
while (<FH>) { $line_total++ }
while (<$FH>) { $line_total++ }
# Reset back to beginning of file and re-read
seek(<FH>,0,0);
seek($FH,0,0);
my $line_current = 0;
my $percent_last = "";
while (my $cmdline = <FH>) {
while (my $cmdline = <$FH>) {
# Bump line number
$line_current++;
# Grab percent done
my $percent_done = sprintf('%5.1f',($line_current / $line_total) * 100);
# If its changed, output and save
if ($percent_done ne $perecent_last) {
sprintf($OUT " Progress: %s",$percent_done);
if ($percent_done ne $percent_last) {
print($OUT " Progress: $percent_done\n");
$percent_last = $percent_done;
}
......@@ -236,7 +237,7 @@ sub loadFile
}
# Close
close(FH);
close($FH);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment