Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

"I guess you meant 'once only' instead of start to finish."

I did not mean that. Perhaps a better way would have been for me to say a beginning of file to end of file manner. All the aforementioned languages support some sort of seek which allows you to change the current position in the file.

The reason that you should not get an error message is because the while(<FILE>){...} is behaving exactly as documented and in my opinion it behaves intuitively.

As stated in perl documentation <FILE_HANDLE> will return undef when there is nothing left to read at the current location in the file (aka the end of the file). Undef evaluates as false and therefore the body of the while loop is never executed. It is important to note that the command did not fail, silently or otherwise. The command behaved exactly as documented. The filehandle is not "already read","expired" or "inactive". There is simply nothing left to be read at the current position in the file.

I believe the primary issue is that your understanding of how file reading should work does not match how file reading actually works on modern operating systems. At the moment I do not have any advice on places to learn more about file reading other than the perldoc.perl.org. Perhaps another PerlMonk would have some additional reference material that would help you better understand files, file descriptors, and file reading.


In reply to Re^5: Trying to do multiple while loops on the same input file by zek152
in thread Trying to do multiple while loops on the same input file by elef

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 having a coffee break in the Monastery: (4)
As of 2024-04-19 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found