Fellows monks,
I ask the enlightment of your wisdom about the following little problem.

As stated in perlfunc, readline(*HANDLE) returns undef at the end of file. The same obviously is true for the IO::File getline method.

I'm writing a class inheriting from IO::File which should read records from a formatted file. Obviously, the main thing to do, maybe the only one, is to redefine getline method.

My getline method looks like this:

sub getline { my $self = shift; my $line = $self->SUPER::getline() || return undef; #the _parse function check if the line is well formed and #returns a hash references filled with informations from #the line. _parse() returns undef if there is a format #error in the line my $result = _parse($line); if (defined $result) { return $result; } else { #this is the tricky part... #what should I do? } }

The problem is that I'm unable to decide what should my method do when the file is not actually at EOF but the current line is malformed. The options appears to be 'the same thing' as IO::File->getline(), but I can not found what this 'thing' is by reading the doc, or die-ing, which would oblige me to always wrap the calls to the method into a eval block.

What I'm asking from your wisdom is then:

  • what does getline return when there is an input error?
  • what should my getline do when it finds a format error?

Thanks for helping.


Leo TheHobbit

update: corrected some typos


In reply to readline error behavior by TheHobbit

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.