Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Is this reliable?

by tobyink (Abbot)
on Feb 18, 2013 at 16:43 UTC ( #1019363=note: print w/replies, xml ) Need Help??

in reply to Is this reliable?

Perl has some special constants that it returns as true and false in response to comparisons and some other boolean expressions. You can peek at the internals of these constants using Devel::Peek:

$ perl -MDevel::Peek -e'Dump(1 < 2)' SV = PVNV(0xa1046e4) at 0xa102520 REFCNT = 2147483644 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0xa1055d0 "1"\0 CUR = 1 LEN = 12 $ perl -MDevel::Peek -e'Dump(1 > 2)' SV = PVNV(0x947a6d0) at 0x9478510 REFCNT = 2147483647 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x947a6c8 ""\0 CUR = 0 LEN = 12

Interesting observations:

  • Note the high REFCNT; this ensures that these constants are never destroyed by the garbage collector.

  • The PV shows you how these constants are stringified. True becomes "1" and false is the empty string.

  • The IV shows you how these constants are converted to integers. True becomes 1 and false is 0.

  • They're read-only...

    $ perl -e'$x = \(1 < 2); $$x++' Modification of a read-only value attempted at -e line 1.

I'm not going to say that these constants are never going to change (never say never!) but it would probably break a lot of code if they did, so I think p5p would be pretty wary of changing this. The Enterprise operator (see perlsecret) relies on them numifying as 0 and 1.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019363]
[stevieb]: I'm learning that no matter how good a piece of software is at what it's supposed to do, it's a piece of shit without providing any API documentation. (Talking about C++ here currently). Seriously... write software for an embedded platform and make...
[stevieb]: guess based on the sparse examples, and the header files that are spread out illogically?
[stevieb]: document the public facing functions/methods people... ALL OF THEM.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-05-28 23:43 GMT
Find Nodes?
    Voting Booth?