in reply to Re^3: Why is Dumper returning "!!1" for true file test?
in thread Why is Dumper returning "!!1" for true file test?

Perl 5.36 does have "new" booleans. Copies of the immortal &PL_sv_yes and &PL_sv_no values are still identifiable as booleans. This means they can be serialized more accurately. The latest versions of JSON::PP, Data::Dumper, and Storable all support this.

Prior to perl 5.36 it was not possible to identify a boolean true value after it had been copied. The exact same SV type, flags, and values could be produced by normal usage of a string "1". A boolean false would be more identifiable as it would never be produced naturally, requiring dualvar to construct.

Replies are listed 'Best First'.
Re^5: Why is Dumper returning "!!1" for true file test?
by ikegami (Patriarch) on Jan 22, 2024 at 16:10 UTC

    Prior to perl 5.36 it was not possible to identify a boolean true value after it had been copied

    This was done by ensuring that the string buffer (PV) of &PL_sv_yes and &PL_sv_no is shared on assignment.

    $ 5.34t/bin/perl -MDevel::Peek -e'Dump(!!1); my $x = !!1; Dump($x);' SV = PVNV(0x55852a177160) at 0x55852a1753c8 REFCNT = 2147483644 FLAGS = (IOK,NOK,POK,READONLY,PROTECT,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x558529a84f64 "1" CUR = 1 LEN = 0 SV = PVNV(0x55852a177220) at 0x55852a178770 REFCNT = 1 FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x55852a1b6010 "1"\0 CUR = 1 LEN = 10 $ 5.36t/bin/perl -MDevel::Peek -e'Dump(!!1); my $x = !!1; Dump($x);' SV = PVNV(0x55d55f1be160) at 0x55d55f1bc3c8 REFCNT = 2147483644 FLAGS = (IOK,NOK,POK,IsCOW,READONLY,PROTECT,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x55d55e89b984 "1" [BOOL PL_Yes] CUR = 1 LEN = 0 SV = PVNV(0x55d55f1be220) at 0x55d55f1bf770 REFCNT = 1 FLAGS = (IOK,NOK,POK,IsCOW,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x55d55e89b984 "1" [BOOL PL_Yes] CUR = 1 LEN = 0

    is_bool checks if the provided scalar shares a string buffer (PV) with &PL_sv_yes or &PL_sv_no.

    Before you had two "levels" of true:

    • &PL_sv_yes
    • true or false value

    After, three:

    • &PL_sv_yes
    • is_bool
    • true or false value