Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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"; }


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


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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2018-06-24 21:40 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.