Home Accessibility Courses Twitter The Mouth Facebook 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))
How are you getting on?

Have you ever asked someone to do something for you ... a long task, and you would like a progress report? "How are you getting on?" you'll ask ... and they'll give you an update - "I'm 75% of the way through" they'll say or - perhaps even more helpfully - "I'm nearly there, and I have some good results coming through" or "this is taking a long time and isn't looking very productive".

Such feedback can be very valuable - it can allow you to plan your next stage, it may allow you to start working already with intermediate results ... or it can give you the options to say "as it's not working out, let's try something else a bit more productive instead / let's not waste time finishing that job".

Can you say "how are you getting on" to a long running Perl program? If you have written the program accept such requests then, yes, you can!

Perl uses signals in the %SIG hash. There are a whole series of external signals that a program can react to including (for the example I wrote during this week's Perl course) ^C (Control - C) which is in $SIG{INT}.

When you want to set up a signal processor, so that you override the default action, simply put the name of the new handler as a text string into the %SIG hash:
  $SIG{INT} = "hello";
Then - whenever ^C is pressed - the sub called hello will be run.

But before you go off and write a long and exciting piece of code in the sub, remember that you can't control your user - (s)he could press ^C at any subsequent point in your program, and cause the extra piece of code to be run at ANY time; that could be in the middle of a loop, it could be between a series of statements that update a database, or at any other inconvenient time where your data / variables / stack are in a transient state. So - please keep your signal handler routine really simple - I usually just set a global variable to a known value (such as "1" to know I have the signal set); I can then check that variable at the end of an iteration / known points in my code, where I generate a status report based on stable conditions, I reset the flag variable, and carry on.

sub hello {
  $ish = 1;

and at the end of my main code loop (after processing the next one of millions of records, perhaps):

if ($ish) {
  print ("$s_x $s_p $s_b\n");
  $ish = 0;

But what if I *really* want to abort my program? Well - I've got a little trick. I make a note of the time that ^C is pressed, and if it's pressed twice within 3 seconds, I sense that my user is getting impatient and I exit from the process ;-). Here's my modified sub hello

sub hello {
  $ish = 1;
  $when = time();
  if ($when - $previous < 3) {
    die("Exiting - multiple ^C\n");
  $previous = time();

The subject is taught on our Perl for Larger Projects course. And also (where it's appropriate, as it was this week) on private Perl courses run for single organizations.

It's implemented within a complete example - at [here], where I was combining 2 files of over 100 Mbytes each, matching up corresponding records, prior to analyzing them.

Further examples from our course material directories ...

Testing with just a sample of data (truncating the run) [here].

A demonstration with good intermediate user feedback (progress bar with info type) [here].

Asking for intermediate results via signals - [here] and [here]

Illustration - delegates on the Perl course which inspired this example and blog

(written 2010-06-13, updated 2010-06-18)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P667 - Perl - Handling Huge Data
  [639] Progress bars and other dynamic reports - (2006-03-09)
  [762] Huge data files - what happened earlier? - (2006-06-15)
  [975] Answering ALL the delegate's Perl questions - (2006-12-09)
  [1397] Perl - progress bar, supressing ^C and coping with huge data flows - (2007-10-20)
  [1920] Progress Bar Techniques - Perl - (2008-12-03)
  [1924] Preventing ^C stopping / killing a program - Perl - (2008-12-05)
  [2376] Long job - progress bar techniques (Perl) - (2009-08-26)
  [2806] Macho matching - do not do it! - (2010-06-13)
  [2834] Teaching examples in Perl - third and final part - (2010-06-27)
  [3374] Speeding up your Perl code - (2011-07-30)
  [3375] How to interact with a Perl program while it is processing data - (2011-07-31)

Back to
Regular Expression Myths
Previous and next
Horse's mouth home
Forward to
Macho matching - do not do it!
Some other Articles
Frankfurt in 90 minutes
From home to Nurnberg - journey pictures
Canal through Melksham - the options and issues
How are you getting on?
Regular Expression Myths
Travelling across Europe
After the Perl course in Nurnberg
Binary data handling with unpack in Perl
The Merchants And
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2805_How ... g-on-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb