Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^5: "last expression" quiz

by sauoq (Abbot)
on Oct 19, 2005 at 22:36 UTC ( [id://501458]=note: print w/replies, xml ) Need Help??


in reply to Re^4: "last expression" quiz
in thread "last expression" quiz

Actually, bart is saying it returns !1 which is really scalar false. It is subtly different than "" as can be seen here:

$ perl -wle 'print "yes" if !1 == 0 ' yes $ perl -wle 'print "yes" if "" == 0 ' Argument "" isn't numeric in numeric eq (==) at -e line 1. yes

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^6: "last expression" quiz
by japhy (Canon) on Oct 19, 2005 at 23:12 UTC
    The difference is more visible this way:
    use Devel::Peek; Dump(""); Dump(!1);
    The output of which is
    SV = PV(0x816d944) at 0x8163c48
      REFCNT = 1
      FLAGS = (PADBUSY,PADTMP,POK,READONLY,pPOK)
      PV = 0x8167830 ""\0
      CUR = 0
      LEN = 1
    SV = PVNV(0x814d6a0) at 0x814c600
      REFCNT = 2147483647
      FLAGS = (PADBUSY,PADTMP,NOK,POK,READONLY,pNOK,pPOK)
      IV = 0
      NV = 0
      PV = 0x814d678 ""\0
      CUR = 0
      LEN = 1
    

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re^6: "last expression" quiz
by Aristotle (Chancellor) on Oct 19, 2005 at 22:42 UTC

    Ah, interesting; I guess Perl DWIMs this so well I had never paid enough attention to notice the subtlety. Reminds me of the games some people played elsewhere on the Monastery quite a while ago with scalars that had specific, different values when evaluated as numbers or as strings (without overloading, if memory serves). (Alas, I cannot remember any useful keywords to Super Search it.)

    Makeshifts last the longest.

        Yes, that’s precisely the kind of thing I’m talking about. The nodes I am thinking of predate Scalar::Util and instead used a bit of voodoo to achieve the effect, though.

        And thanks for pointing me that way – I didn’t know Scalar::Util had such a utility function. Plus now I see several new interesting functions in recent versions that I hadn’t noticed before. I need to do some homework here!

        Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found