Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
while(my $line = $reader->get_next_line()){

I just wanted to point out that this suffers from the same issue that AnomalousMonk correctly pointed out deeper in the thread: if the file ends on a line containing just "0" with no newline, this loop won't catch that. You would have to say while( defined( my $line = $reader->get_next_line() ) ) instead. Alternatively, note it's possible to overload the <> operator (note that overloaded <> in list context wasn't implemented until 5.18). See for example my use in Algorithm::Odometer::Tiny; you'd just have to change $self->() to your method call, and then you could write while( my $line = <$reader> ) and Perl will automatically add the defined call.

By the way, in your post here, I don't understand the point of the two $self->{file} = shift; lines, especially the second one? Why change the filename while reading the file?


In reply to Re: What's the right way to write a method which returns one line at a time from a file? by haukex
in thread What's the right way to write a method which returns one line at a time from a file? by Cody Fendant

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 goofing around in the Monastery: (5)
As of 2024-04-25 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found