Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found