Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: Is this reliable? by tobyink
in thread Is this reliable? by misterperl

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (6)
    As of 2018-06-25 16:17 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (127 votes). Check out past polls.