Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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


In reply to Different perl behavior between V5.10 and V5.14 by markseger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (9)
    As of 2014-07-10 08:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (202 votes), past polls