Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Critique of some perl code.

by Fletch (Bishop)
on Apr 18, 2022 at 14:30 UTC ( [id://11143052]=note: print w/replies, xml ) Need Help??


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

Doing a while where the conditional is a function of a filehandle iterator (or a couple other iterater-y things) has implicitly done the defined test whether or not there's an assignment to a variable for a while now.

If the condition expression of a "while" statement is based on any of a group of iterative expression types then it gets some magic treatment. The affected iterative expression types are "readline", the "<FILEHANDLE>" input operator, "readdir", "glob", the "<PATTERN>" globbing operator, and "each". If the condition expression is one of these expression types, then the value yielded by the iterative operator will be implicitly assigned to $_. If the condition expression is one of these expression types or an explicit assignment of one of them to a scalar, then the condition actually tests for definedness of the expression's value, not for its regular truth value.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^3: Critique of some perl code.
by afoken (Chancellor) on Apr 21, 2022 at 07:26 UTC
    [...] has implicitly done the defined test [...] for a while now

    Do you know which version introduced that?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      It’s been a while but not specifically no. I may go diving through perldeltas because I’m curious myself.

      Edit: So . . .

      • perl5280delta notes the changes to the while documentation to its current state (commit 5e979393c70, issue).
      • perl518delta notes that while(each %h) was changed to imply while(defined($_ = each %h)) using the phrasing "like readline and readdir" so it's present before then.
      • The oldest possibly related change I've found was commit 54310121b44 which rolls up patches 5.003_86..5.003_95 where it changes perlsyn where the explicit version of the while loop given in the "Loop Control" section has a defined($line = <ARGV>) conditional, so I'm guessing it's possibly a 5.004-ism . . .
      • stopping poking for now . . .

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-18 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found