in reply to (Ovid) Re: need nextline() sub
in thread need nextline() sub

Zaxo was on the money with readline() - all i needed was to get underneath the abstraction of the <FH> operator.
package FileClerk; open (FH,$file); sub next_line { return (readline(*FH)); }
calling program:
use FileClerk; for (FileClerk::next_line()) { print "$_\n"; }
The calling program doesn't need to care about the filehandle, which was my aim. Thanks everyone.

Replies are listed 'Best First'.
Re3: need nextline() sub
by Hofmator (Curate) on Nov 22, 2001 at 23:59 UTC

    Zaxo was on the money with readline() - all i needed was to get underneath the abstraction of the <FH> operator.

    The spaceship operator (<>) is just a wrap around the readline function. You can get the same behaviour like this:

    sub next_line { return scalar <FH>; }

    Another remark, it might be worth setting $/ before using readline. That way you don't get unexpected behaviour if someone fiddled with it. So put something like this at the start of your sub:

    local $/ = "\n";

    -- Hofmator