Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^8: Regex result being defined when it shouldn't be(?)

by chenhonkhonk (Acolyte)
on Nov 16, 2017 at 18:37 UTC ( [id://1203613]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Regex result being defined when it shouldn't be(?)
in thread Regex result being defined when it shouldn't be(?)

 defined($var)==0
Use of uninitialized value in numeric eq (==)

use strict; use warnings; my $variable = undef; if( undef == 0 ){ print "undef == 0\n"; } if( $variable == 0 ){ print "\$variable undef == 0\n"; } if( "" == 0 ){ print "\"\" == 0\n"; } if( undef eq 0 ){ print "undef eq 0\n"; } if( undef eq 0 ){ print "\$variable undef eq 0\n"; } if( undef eq "" ){ print "undef == \"\" \n"; } if( 0 == "0" ){ print "0 == \"0\"\n"; } if( 0 eq "" ){ print "0 eq \"\""; } if( undef eq "" ){ print "undef == \"\"\n"; } if( defined ($variable) eq "" ){ print "undef == \"\"\n"; } exit 0;
The last two cases may be of particular interest. undef is uninitialized as itself or from a variable, but as the result of defined it is not uninitialized. Magic conditions. I'm running Perl 5.26.1

Nvm: doy. Defined returns "" on undef.

Replies are listed 'Best First'.
Re^9: Regex result being defined when it shouldn't be(?)
by soonix (Chancellor) on Nov 18, 2017 at 11:32 UTC
    defined($var)==0
    Do you also write conditios as
    if ( ($var < $threshold) == TRUE ) ...
    ? Then why not
    if ( ( ($var < $threshold) == TRUE ) == TRUE ) ...
    or more?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2025-12-17 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (98 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.