Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Monitoring a Perl program

Posted by enquirer (enquirer), 9 February 2004
I have a Perl program that takes a long time to run.  How can I check up on its progress - I want to know if it has got into an infinite loop or not, or if it's still running just how much longer it's likely to take  

Posted by admin (Graham Ellis), 9 February 2004
Big question this one - lots of possible answers and options.  

For starters, if your program has a big loop that occupies most of the time you might like to put a printf statement in there, output to STDERR rather that STDOUT, and give the loop count, percentage of the way through, or something like that.   Here's a code sample:
select STDERR;
$| = 1;
select STDOUT;
$top = 15;
foreach (1..$top) {
       $now = sprintf ("%3d%% through",$_*100/$top);
       print  STDERR "\r$now";
       sleep 1;
print  STDERR "\n";

Few things to note:
* $| turns on autoflush mode (so that your carefully added alerts don't just get buffered).  
* \r is used rather that \n to ensure that each alerts overrights the previous
* printf is used to ensure all lines are the same length

If you have a loop that goes round "millions" of times, you won't want to print in every loop - follow your print statement with
           if (++$freq%50 == 0)
or something like that - it will print just one line in every 50!

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho