Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Critique of some perl code.

by jwkrahn (Abbot)
on Apr 18, 2022 at 03:00 UTC ( [id://11143043]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11143043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found