I also agree that the old style file open is not an issue - should work fine. Apero's post shows what can happen if the file is "empty", you would get EOF.

If the writer of this file has it open, it is possible for there not to be anything in it yet, but yet possible for you to have it open for read. One of those reasons could be output buffering. Typically the writer will have to "write" at least 1K before the data gets flushed to the disk.

Perl has some built file test operators, my $size = -s $filename should give you the current file size that you are able to read.

So without fixing the writer to turn off buffering, by say adding $|=1, you could loop for a while, checking $size every second or so (sleep(1) or whatever) for a few minutes. Don't try to read from the open filehandle until $size>0. Usually once you hit "EOF", you can't read past that, but you can delay reading until something is actually available for you to read. That way you won't hit EOF.

Basically this idea just automates the "wait a few minutes" and try again part. Also adding this $size check to the code would I think be of diagnostic value, if you are getting undef read value (EOF) and $size>0, then there is some other problem.

PS: what O/S are you using?

Update: Perl File Test Operators


In reply to Re: Able to open file, unable to read by Marshall
in thread Able to open file, unable to read by feiiiiiiiiiii

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.