Hello monks
Why won't the following code work? Basically I want to reopen a file (cheesy man's tail) and look for errors and warnings. The problem is I kept getting this in the output
readline() on closed filehandle main::LOG at ./netlist.pl line 510.

which used this code
my $log = "$cell".".$$"."/si.log"; my $pwd = cwd(); my $netlist = "$pwd"."/"."$cell".".$$"."/"."$cell".".cdl"; my ($error, $done) = 0; print " Checking log files for success on $netlist\n"; while (( ! $error ) and ( ! -f $netlist)) { open ( LOG, $log ) || warn " Couldn't open log\n" if ($debug); while (<LOG> ){ print "$_"; if ( ($_ =~ m/error/i) or ($_ =~ m/warning/i) ){ print "$_" ; print "$_" if ($debug) ; if ($_ =~ m/error/i) { $error = 1; print "$_"; $icfb->hard_close(); } } close LOG; } sleep 2; }
Ok fine, I thought it was re-opening the thing so many times, it barfed. That's ok, just check the file everyonce in a while. So I started looking to see if fileno was defined. It NEVER get's defined. Can someone please point me in the right direction..
my $log = "$cell".".$$"."/si.log"; my $pwd = cwd(); my $netlist = "$pwd"."/"."$cell".".$$"."/"."$cell".".cdl"; my ($error, $done) = 0; print " Checking log files for success on $netlist\n"; while (( ! $error ) and ( ! -f $netlist)) { open ( LOG, $log ) || warn " Couldn't open log\n" if ($debug); if ( defined (fileno LOG )) { print "Defined \n"; while (<LOG> ){ print "$_"; if ( ($_ =~ m/error/i) or ($_ =~ m/warning/i) ){ print "$_" ; print "$_" if ($debug) ; if ($_ =~ m/error/i) { $error = 1; print "$_"; $icfb->hard_close(); } } } close LOG; } else { print "Not Defined\n"; } sleep 2; }
FWIW, I also tried to use File::Tail but I couldn't figure out how to do a conditional if no errors and no netlist keep going..

Rhodium

The seeker of perl wisdom.


In reply to Filehandle open or not - WTF? :( by Rhodium

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!
  • 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, details, 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, summary, 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.