in reply to Re: Critique of some perl code.
in thread Critique of some perl code.

This is pretty reasonable if as a non-expert you are vaguely aware that while ($line = <$fh>) has some differences around termination conditions compared to while (<$fh>).

What "termination conditions" are different between them?

Replies are listed 'Best First'.
Re^3: Critique of some perl code.
by AnomalousMonk (Archbishop) on Apr 18, 2022 at 05:41 UTC

    I was also puzzled by the differing "termination conditions." I don't see them.


    Give a man a fish:  <%-{-{-{-<

Re^3: Critique of some perl code.
by hv (Prior) on Apr 18, 2022 at 17:32 UTC

    I think it's no longer true - and I'm struggling to remember how to test it - but I'm pretty sure there used to be the distinction that while (<>) was special-cased to act as while (defined($_ = <>)), while anything more complicated (such as while ($line = <>)) did not get the "defined" check added to it. So if <> were to return something like an empty string, or "0", the latter case could terminate early.

    The oldest perl I have to hand is a maint-5.8, and I couldn't reproduce it there with perl -e 'print "0\n0"' | perl -we 'while ($r = <>) { printf "%s", $r }' -, so either I'm testing it wrong, or it affected only even earlier perls, or I'm going senile. (These options are not necessarily exclusive.)

    Update but the point was that it could be written by someone with a vague memory that something like that could happen - much like I have - and if so, that didn't necessarily make it awful code.