I have had to load large text files(500MB - 2GB+) into a database (SQL Server). After I had been asked several times how it was progressing, I decided I would implement a simple counter so that I could show them whenever they asked.
This simple little bit proved very useful for my own purposes as well because loading a database table could take hours and it was important to see for myself that it was still running.
I hope this proves useful to some of you. Cheers, mrmick
# these represent what we will use to track the information my $record_cnt = 0; my $GCOUNT = 0; my $initcnt = 0; # counts the records in the file.... sub get_record_count{ my $file = shift @_; open(FILE,$file)|| die"Cannot open $file\n$!\n"; print "Counting records........\n\n"; while(<FILE>){ $initcnt++; } close(FILE); } # end get_record_count sub count_record{ $record_cnt++; $GCOUNT++; if($record_cnt == 100){ $record_cnt = 0; my $status = (($GCOUNT/$initcnt)*100); printf("\r %.2f\% Complete ",$status); } } # end count_record
|
|---|