in reply to Re^2: What's the right way to write a method which returns one line at a time from a file?
in thread What's the right way to write a method which returns one line at a time from a file?
if ( my $line = readline( $self->{file_handle} ) ) { return $line; } else { return; }
I appreciate old-school, but I think the quoted code will fail to return the last line of a file if it is '0' with no terminating newline. I haven't tested it, but wouldn't
or even justif (defined(my $line = readline( $self->{file_handle} ))) { return $line; } else { return; }
return readline($self->{file_handle});
(readline returns undef at eof) be better?
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: What's the right way to write a method which returns one line at a time from a file?
by Cody Fendant (Hermit) on Nov 28, 2020 at 03:16 UTC |
In Section
Seekers of Perl Wisdom