in reply to Re: "" but true
in thread "" but true

> For $x to be True, its first (number) argument needs to be true in numeric context && its second (string) argument needs to be true in string context.

Do you have a reference for this, or is it a guess?

I'm surprised since

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: "" but true
by syphilis (Archbishop) on May 14, 2021 at 03:20 UTC
    Do you have a reference for this, or is it a guess?

    I thought I had a reference for this ... but no, I completely misread this statement in the docs, relating to isdual():
    If $var is a scalar that has both numeric and string values, the resul +t is true
    Not only does it not pertain to dualvar(), but it doesn't say what I thought it said, anyway !!
    Additional experimentation suggests that, in fact, the dualvar will be True if the second arg is True. Is that the correct summation ?
    Thanks for catching.

    Not sure if that mistake necessarily impacts upon the little overload demo I provided.
    In any case, of course, that overload_true() subroutine can be tweaked to make it do whatever you want.

    I'll edit that post of mine.

    Cheers,
    Rob
        I followed your link.
        I did say the "the dualvar will be True if the second arg is True", and the second arg is the stringy arg.
        But you're right, I could have been more explicit - especially since LanX had speculated in the direction of "numeric context".
        (I missed an opportunity to score a point there !! ;-)

        Cheers,
        Rob
        Yeah this makes sense since the string " " is true while it's numeric value is 0, so the stringy part must be tested if available.

        DB<50> $a=" " DB<51> $b = $a+0 # $a will cache its numeric val DB<52> p !!$a # still true 1 DB<53> use Devel::Peek DB<54> Dump $a SV = PVNV(0x3fbd6f8) at 0x4aeebe0 REFCNT = 1 FLAGS = (POK,pIOK,pNOK,pPOK) IV = 0 # <-- integer NV = 0 PV = 0x4c4fb58 " "\0 # <-- string CUR = 1 LEN = 10 DB<55> Dump $b SV = NV(0x4aeedf0) at 0x4aeee08 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 0 DB<56>

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery