SPUG: "Boolean" return values
Colin Meyer
cmeyer at helvella.org
Mon Oct 13 15:32:35 PDT 2008
On Mon, Oct 13, 2008 at 03:03:26PM -0700, Michael R. Wolf wrote:
> Does anyone know the motivation for the return values from the boolean
> operators?
We have boolean context, but not boolean operators. Maybe "!". Most of
the logical operators have return values based on their input.
>
> true returns (numeric) 1
> false returns (string) ''
>
> Why not just 0 and 1? Why the mix of numeric and string?
They return a multi-valued scalar:
> perl -MDevel::Peek -le'Dump( ! "" ); Dump( ! 0 );'
SV = PVNV(0x605060) at 0x2af2764040d0
REFCNT = 2147483647
FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK)
IV = 1
NV = 1
PV = 0x606030 "1"\0
CUR = 1
LEN = 8
SV = PVNV(0x605060) at 0x2af2764040d0
REFCNT = 2147483647
FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK)
IV = 1
NV = 1
PV = 0x606030 "1"\0
CUR = 1
LEN = 8
In a string context, that will be "1"; Integer or real: 1; Boolean: true;
The return values for false are similarly multivalued.
-Colin.
More information about the spug-list
mailing list