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

Re: Logical expression evaluation

by benizi (Hermit)
on Jul 27, 2005 at 20:55 UTC ( [id://478717]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Logical expression evaluation
in thread Logical expression evaluation

Wrong. Perl false is !1. (PL_sv_no in the C source) It's a dualvar with a string value of "" and a numerical value of 0.

See: Re^4: m//g behaves strange... (!1). And this snippet:

$ perl -lwe 'for (qw/undef 0 "" !1 1==2/) { print "\n\$a = eval $_;"; +$a = eval $_; print "$_:\t|$a|", 1+$a; }' $a = eval undef; Use of uninitialized value in concatenation (.) or string at -e line 1 +. Use of uninitialized value in addition (+) at -e line 1. undef: ||1 $a = eval 0; 0: |0|1 $a = eval ""; Argument "" isn't numeric in addition (+) at -e line 1. "": ||1 $a = eval !1; !1: ||1 $a = eval 1==2; 1==2: ||1

Replies are listed 'Best First'.
Re^2: Logical expression evaluation (dualvar)
by bart (Canon) on Jul 27, 2005 at 21:07 UTC
    And nowadays, you can have the magic of dualvars for your own evil plots applications, using dualvar() from Scalar::Util.

    BTW another typical magical dualvar value is $!, which returns an error message as a string, and an error number as a number. For example:

    local $\ = "\n"; $! = 3; # error number print $!; # error message print 0+$!; # error number

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (None)
    As of 2024-04-25 01:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found