http://qs321.pair.com?node_id=11115855


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.