mje has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a problem making a patch to a module work which contains the following code:

/* sv contains "aa" i.e., SvPOK(sv) is true and pv="aa" sv_2nv(sv); cast_ok = SvNOK(sv); /* now cast_ok contains 512! */ /* and SvNV(sv) is 0 */

sv contains "aa" in pv and was created by $val = "aa". Printing SvPV_nolen confirms pv contains "aa". Since "aa" is not a valid double then why is SvNV true and why does SvNV return 0?

Replies are listed 'Best First'.
Re: Why does sv_2nv on non-number look like an NV
by Anonymous Monk on Nov 26, 2009 at 13:51 UTC
    Because sv_2nv turns it into a double?

      How can you turn "aa" into a double?

        With difficulty. You get zero
        >perl -e"print 0+'aa'" 0