> >:    $FH = open "<$file" or die "Can't open $file: $!";
> >:    $line = next $FH;
> >:
> >: If so, I can live with that.
> >
> >Yes, that's the reason it's C<next>, and not something more specific
> >like C<readline>, which isn't even true in Perl 5 when $/ is mungled.
>
> I dunno. Color me unconvinced--I do use the <> enough in non-while context
> (and in non-implied while context) to make the whole idea of next feel
> rather... nasty. And $FOO.next? Yuck.

You know, I was just thinking about this, and I agree with Dan. Actually,
there's some big problems in trying to get rid of <> and make Perl do the
"right thing" in boolean context (like the while loop example). Consider:

   $FH = open "</etc/motd";
   die "No good" unless ($FH);    # ???

What does that do? Per the proposal, $FH in a boolean context is supposed to
call its next() method to get the next line. So, does that fail because the
handle wasn't opened (and hence $FH was never defined) or because /etc/motd
is zero-length?

And having to write "$line = next $FH" is already getting cumbersome, to be
honest.

I say we should combine the two concepts. Why not make <> a shortcut to the
proposed new general-purpose-iterator concept? So:

   $line = $FOO.next;        # yuck, I agree with Dan
   $line = next $FOO;        # better...
   $line = <$FOO>;           # aaah :-)

   print while ($FOO);       # infinite, assuming $FOO defined
   print while ($FOO.next);  # while reading the file
   print while (<$FOO>);     # still my favorite

Otherwise, it seems like there's a lot of Black Magic with calling next()
automatically, and for something as fundamental as I/O that makes me really
nervous.

-Nate


Reply via email to