Stupid Perl Trick
Ofter, I remember a stupid little thing I did in Perl once that I can’t find again. The problem is I can’t remember where I put it. So I’m putting this here with hopes to remember to look next time I need it.
Usually when I wish to print the progress of something that takes a long time I use CPAN‘s Term::ProgressBar
, but you need to know how many elements you have to do this. Instead I thought it would be cool to keep track of time, but printing time - $^T
gets sort of meaningless after a few hours of running. So, the quicky, super-duper, way to print out h:mm:ss seems to be, where $t
holds the number of seconds so far: printf STDERR "$0: %d:%02d:%02d\n", $t/(60*60), $t/60 % 60, $t % 60;
And this prints it out with little fuss. A little stupid to make public, but nobody reads my logs anyway.