in reply to perl program status
First, build a standard subroutine to do all your output for you. Mine follows. It prints my status messages where I want them as well as the message index, the time, and the elapsed time.
Before every major section, Log what you are about to do. Give the message a nice bold start so you know you're at a major heading. If you are processing and you want status of the processing, put an if statement in your loop and print some status every 1000 iterations or whatever is apropriate. If it's really heavy processing, the single if shouldn't slow you down too much, especially if you're calling subroutines, at least if Fundamental Benchmarks has any validity. Put some dashes in front of the message so you know you're in a subsection. I also like to throw in some extra processing to give me an Estimated Time To Completion. I have never ever seen this value be very accurate, as programs tend to slow down after a while of heavy processing. But I do it anyway.
Hope this helps!
my $Start_Time = time; my $LogFile = "logfile.log"; my $ProgressIndex = 1; my $i = 0; EnterIntoLog ("My freaky message"); $i *= $i for (1..10000000); EnterIntoLog ("Another message"); sub EnterIntoLog { my $message = shift; my $Now = time; my $Seconds_Past = int ($Now - $Start_Time); my $Minutes = int ($Seconds_Past/60); my $Seconds = $Seconds_Past % 60; my $ProgressString = sprintf ( "%05d\t" . localtime($Now) . "\t%02d:%02d\t$message\n", $ProgressIndex++, $Minutes, $Seconds); print $ProgressString; open LOG, ">>$LogFile" or die "Can't open $LogFile: $!\n"; print LOG $ProgressString or die "Can't print to $LogFile: $!\n"; close LOG or die "Can't close $LogFile: $!\n"; }
|
|---|