Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Different perl behavior between V5.10 and V5.14

by Loops (Hermit)
on Apr 01, 2013 at 12:23 UTC ( #1026472=note: print w/ replies, xml ) Need Help??


in reply to Different perl behavior between V5.10 and V5.14

Bit of an odd one. As a data point, unable to reproduce the problem here on Fedora 17, with either the system 5.14 perl, or 5.16.


Comment on Re: Different perl behavior between V5.10 and V5.14
Re^2: Different perl behavior between V5.10 and V5.14
by markseger (Beadle) on Apr 01, 2013 at 12:39 UTC
    Since what it currently happening is the code is reading the new record, printing it and then immediately exiting the loop, I inserted an eof() before trying to read the pipe from the pipe and did verify eof() is returning a 1. So I put in some code to call eof() before trying to read and if it returns 1 to simply do a read I know will fail and then follow it with next to stay in the inner loop.

    Seems to work just fine but it doesn't make me happy. Perhaps this might offer a clue to someone else who does know what's going on?

    -mark

      Hm. Weird. I've modified code like this:
      #!/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>) { $X = $!; print $line; } if (eof(TAIL)) { print "EOF TAIL!\n"; } print "Fell through... $!\n"; } sub sigAlarm { print "alarm\n"; }
      After first EOF found, it never works normal again. It just prints EOF TAIL + Fell through... in infinite loop. So, I think filehandle never recovered after Perl finds EOF.
        I think the problem is once you've done the first $line=<TAIL> it's too late. Here's what I wrote that DOES work correctly and will not exit the loop, but as I said I'm not proud of it ;):

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

        I also wonder if doing that eof() test at the beginning go throw me into an infinite loop under some conditions, but as so far this seems to be ok for now.

        -mark

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026472]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (18)
As of 2014-08-27 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (242 votes), past polls