Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Matching against $_ behaves differently than matching against a named scalar?

by davido (Cardinal)
on Apr 21, 2020 at 03:08 UTC ( [id://11115855]=note: print w/replies, xml ) Need Help??


in reply to Re: Matching against $_ behaves differently than matching against a named scalar?
in thread Matching against $_ behaves differently than matching against a named scalar?

I want to clarify something based on documentation from perlop:

while (my $line = <STDIN>) { print $line }

In these loop constructs, the assigned value (whether assignment is automatic or explicit) is then tested to see whether it is defined. The defined test avoids problems where the line has a string value that would be treated as false by Perl; for example a "" or a "0" with no trailing newline.

So in this case the defined test doesn't need to be done explicitly, it's already being done implicitly.


Dave

  • Comment on Re^2: Matching against $_ behaves differently than matching against a named scalar?
  • Download Code

Replies are listed 'Best First'.
Re^3: Matching against $_ behaves differently than matching against a named scalar?
by jcb (Parson) on Apr 22, 2020 at 01:29 UTC

    You are correct. I had forgotten about that particular bit of DWIM, since I do not rely on it in my own code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-20 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found