in reply to Re^2: Booleans from flip-flops
in thread Booleans from flip-flops

It's not an empty string, but a dualvar that has zero is the numeric slot and an empty string in the string slot.
$ perl -wle'print ""' $ perl -wle'print 0+""' Argument "" isn't numeric in addition (+) at -e line 1. 0 $ perl -wle'print !1' $ perl -wle'print 0+!1' 0

Anyway the wording "it returns a boolean value" is somehow misleading ...

It does return something that's a boolean value (true when there's a match, false when there's no match). It also returns ...

Replies are listed 'Best First'.
Re^4: Booleans from flip-flops
by LanX (Saint) on Jan 20, 2010 at 18:54 UTC
    Fascinating, I never heard about dualvars nor that scalars have slots...

    Seems only to be explained in Scalar::Util

    Cheers Rolf

      IV - holds signed int, unsigned int or ref NV - holds float PV - holds string

      And then there are fields to support magic lvalues and general magic.

      Not every field is available at all times. SVs (scalars) have a head which contains a pointer to the body. The body is automatically upgraded when needed (e.g. my $x = 1; $x += 0.1;, tie my $x, ..., etc).

      And even if the field is available, not all values are available at all times. Flags indicate which fields are initialised and what they contain.

      $ perl -MDevel::Peek -e' my $x; Dump $x; $x = 123; Dump $x; "$x"; Dump $x; ++$x; Dump $x; $x=undef; Dump $x; ' Fresh var, no body, no content: SV = NULL(0x0) at 0x88c6920 REFCNT = 1 FLAGS = (PADMY) After assigning int, body upgraded to IV (has field IV), and IV field contains a number (IOK): SV = IV(0x88c691c) at 0x88c6920 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 123 After using content as string, body upgraded to PVIV (has fields IV and PV), IV field contains a number (IOK), and PV field contains a string (POK): SV = PVIV(0x88c56ac) at 0x88c6920 REFCNT = 1 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 123 PV = 0x88e7710 "123"\0 CUR = 3 LEN = 4 After using content as a number, IV field contains a number (IOK), and PV field isn't being used (!POK): SV = PVIV(0x88c56ac) at 0x88c6920 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 124 PV = 0x88e7710 "123"\0 CUR = 3 LEN = 4 After clearing the contents, IV field isn't being used (!IOK), and PV field isn't being used (!POK): SV = PVIV(0x88c56ac) at 0x88c6920 REFCNT = 1 FLAGS = (PADMY) IV = 124 PV = 0x88e7710 "123"\0 CUR = 3 LEN = 4
        Thanks, this reminded of the panther book (1st print). Thankfully I found an old copy in a local library.

        It's the best compilation of perl internas I found till today...always wanted to work through it in detail!

        ... a pity it's not continued anymore! 8(

        Any other recommendations for perl opcodes and internal data formats?

        Cheers Rolf