This has probably been done better by some of you but I like the code here and thought I could share it with my fellow monks.

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 placed the declarations where they could be seen by both subroutines.
get_record_count is called before loading any data (preferably before opening a connection to the database).
count_record is called from within the loop that iterates through the input file while loading the database.

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