http://www.perlmonks.org?node_id=1026468

markseger has asked for the wisdom of the Perl Monks concerning the following question:

I have no idea if this is perl or ubuntu, as this works find on an Ubuntu/natty distro running perl 5.10 and does not do what I expect on Ubuntu/precise running perl 5.14.

The simple problem statement is I want to tail a file and count various types of entries, writing intermediate counters to a file every second. My solution, which has been running just fine for over a year is to simply set a timer with ularm to wake me every second at which time I write my counters and continue.

To reproduce the behavior, first you create the file xyz and then run the script which I've posted after the results. Then in a different window run the command: "echo test >> xyz" a couple of times.

On natty you see:

alarm alarm test alarm alarm test

In other words it stays inside the loop processing the tail command. But the identical test on precise produces the following, noting which each new line written to the file it breaks out of the inner loop:

alarm alarm alarm test Fell through... alarm alarm test Fell through... alarm alarm

I've been trying a variety of things to get this to do what I want and am out of ideas. Here's the code:

#!/usr/bin/perl -w use Time::HiRes; $SIG{"ALRM"}=\&sigAlarm; my $interval=1; my $uInterval=$interval*10**6; Time::HiRes::ualarm($uInterval, $uInterval); open TAIL, "tail -f xyz|" or die 'couldnt open xyz'; while (1) { while ($line=<TAIL>) { print $line; } print "Fell through...\n"; } sub sigAlarm { print "alarm\n"; }

thoughts?

Update...
Now here's somethign really odd I also just discovered. If I run my second 'echo test' before the second consecutive alarm fires, it doesn't fall through the loop! Look at this, noting I waited a couple of second before doing the fourth echo command:

alarm alarm test Fell through... alarm test <<< stayed in loop alarm test <<< stayed in loop alarm alarm alarm test Fell through... alarm

-mark