Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: The mystery of double negation

by shmem (Chancellor)
on Jul 12, 2015 at 17:20 UTC ( #1134403=note: print w/replies, xml ) Need Help??


in reply to The mystery of double bitwise negation

The point of Double Negation is casting any true value to 1, and any false value to 0.

See also: Re^2: Secret Perl Operators: The Highlander List Asserter

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: The mystery of double negation
by hurricup (Pilgrim) on Jul 12, 2015 at 17:34 UTC

    Nope, it's bitwise negation and doesn't work this way. It's basically - noop. Keeps value the same.

      The point of Double Negation is casting [...] any false value to 0.
      Nope, it's bitwise negation and doesn't work this way. It's basically - noop. Keeps value the same.

      Um:

      % say "(!1)" % say "~~(!1)" 0

      So it could be an idiom that is applied to all Boolean values (so that Boolean false shows up as '0' instead of as the "invisible" ''). It just does nothing when the Boolean value is already 1.

      - tye        

        Interestingly, !1 is "", ~~(!1) is 0, but ~~("") is "".
        $ perl -MO=Deparse -E'say !1; say ~~(!1); say ~~("");' use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch' +, 'unicode_strings', 'unicode_eval'; say !1; say 0; say ''; -e syntax OK

      Right you are. Then... maybe chromatic can enlighten us?

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      You're right, but, still, ~~1 will return 1, i.e a true value. Why the author of the module did that, I have no idea.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2022-05-20 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (73 votes). Check out past polls.

    Notices?