Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Dualvars besides $!

by moritz (Cardinal)
on Jan 27, 2014 at 17:11 UTC ( #1072250=note: print w/ replies, xml ) Need Help??


in reply to Dualvars besides $!

Not a variable, but a value: the value for false, which you can generate with !1.

It return '' in string context and 0 in numeric context, and doesn't warn in numeric context like the empty string normally does:

$ perl -wE 'say 0+""' Argument "" isn't numeric in addition (+) at -e line 1. 0 $ perl -wE 'say 0+!1' 0

My version of Scalar::Util doesn't export an is_dual function, so I can't check. It helps to type that without the _ :-)

Update: I should have mentioned it earlier: even though the thing is called a "dualvar", it's not actually variables that are tested; values are being tested. It makes no difference if those values are return values, stored in array, or are stored in a scalar variable.


Comment on Re: Dualvars besides $!
Select or Download Code
Re^2: Dualvars besides $!
by szabgab (Priest) on Jan 27, 2014 at 17:36 UTC
    wow !1. I have not heard of that earlier. greping the pods of 5.18.2 - it is not mentioned there either. But it works as you showed.
Re^2: Dualvars besides $!
by davido (Archbishop) on Jan 27, 2014 at 18:05 UTC

    A value for "true" is also dualvar:

    perl -MScalar::Util -E 'say Scalar::Util::isdual(!0)'

    ...outputs '1', indicating the test was true.


    Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2014-09-23 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (220 votes), past polls