I think it is mainly Data::Dumper being anal: Perl has a builtin constant called PL_Yes PL_sv_yes which is used internally for the boolean true value. The Dumper output is effectively saying that this isn't just any old constant 1, but the one and only PL_sv_yes. For a data structure with many copies I guess you'd get something of a memory saving compared to having many unique SVs.

You can see the difference with Devel::Peek:

perl -MDevel::Peek -wle 'Dump(1); Dump(!!1)' SV = IV(0x56346851ef48) at 0x56346851ef58 REFCNT = 1 FLAGS = (IOK,READONLY,PROTECT,pIOK) IV = 1 SV = PVNV(0x5634684f6050) at 0x5634684f43c8 REFCNT = 2147483644 FLAGS = (IOK,NOK,POK,READONLY,PROTECT,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x563467d5e282 "1" CUR = 1 LEN = 0

Builtins like this have an artificial refcount around 2^31 to indicate "should never be freed, not even accidentally".

Perl v5.36 introduced an actual boolean type, but that doesn't make any noticeable difference to the value except that Devel::Peek now annotates the PV as "[BOOL PL_Yes]".

Update: corrected the internal name of the SV; thanks @ikegami.


In reply to Re: Why is Dumper returning "!!1" for true file test? by hv
in thread Why is Dumper returning "!!1" for true file test? by nysus

Title:
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, details, 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, summary, 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.