Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by haukex (Archbishop)
on Nov 14, 2017 at 16:55 UTC ( [id://1203404]=note: print w/replies, xml ) Need Help??


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

defined $var ... will return undef (which is a FALSE value) if the variable is undefined.

Sorry, that's not quite correct, compare the outputs of the following:

$ perl -wMstrict -MDevel::Peek -le 'my $x = undef; Dump( $x )' $ perl -wMstrict -MDevel::Peek -le 'my $x = !1; Dump( $x )' $ perl -wMstrict -MDevel::Peek -le 'my $x = defined(undef); Dump( $x ) +'

(Update: Whoops, just saw your update, you saw that yourself)

The rest of your post is excellent though, so no worries about the duplicated efforts, TIMTOWTDI :-) I especially like the comparison with C, and it makes another important point: comparing a true/false value explicitly is brittle: If defined decided to return 0 as a false value instead, then defined(...) eq "" will break!

Log In?
Username:
Password:

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

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





    Results (65 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.