[32773] in Perl-Users-Digest
Perl-Users Digest, Issue: 4036 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 20 20:43:03 2013
Date: Wed, 18 Sep 2013 00:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Sep 2013 Volume: 11 Number: 4036
Today's topics:
Re: Return values of boolean operators <peter@makholm.net>
Re: Return values of boolean operators <rweikusat@mobileactivedefense.com>
Re: Return values of boolean operators <rweikusat@mobileactivedefense.com>
Re: Return values of boolean operators <rweikusat@mobileactivedefense.com>
Re: Return values of boolean operators <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 17 Sep 2013 08:00:51 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Return values of boolean operators
Message-Id: <87ioy0asx8.fsf@vps1.hacking.dk>
tmcd@panix.com (Tim McDaniel) writes:
> In article <87ob7tb5hw.fsf@vps1.hacking.dk>,
> Peter Makholm <peter@makholm.net> wrote:
>>See the perlop man page under the heading "Relational Operators".
>
> I'm afraid that's not so in the Perl 5.14.2 installation. That
> section has only
No, it seems to have been added in the documentation for 5.16:
Perl operators that return true or false generally return values that
can be safely used as numbers. For example, the relational operators
in this section and the equality operators in the next one return 1
for true and a special version of the defined empty string, "" , which
counts as a zero but is exempt from warnings about improper numeric
conversions, just as "0 but true" is.
//Makholm
------------------------------
Date: Tue, 17 Sep 2013 10:02:41 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Return values of boolean operators
Message-Id: <8738p3g6ry.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Peter Makholm <peter@makholm.net>:
>> tmcd@panix.com (Tim McDaniel) writes:
>>
>> > OK, which man page is it that has documentation of the return values
>> > of boolean operators? 1 and '', but I dimly recall that there's
>> > something special about the particular '' returned for false, that it
>> > avoids ... um, some kind of warning if ... something ...
>>
>> See the perlop man page under the heading "Relational Operators".
>>
>> Basically it returns a dualvar, not quite unlike what is returned by
>>
>> Scalar::Util::dualvar(0,"")
>
> Exactly the same, in fact, except for PL_sv_no (the internal name of the
> standard 'false' value) being a readonly constant. That means that this
>
> my $x = \!1;
> $$x = 1;
>
> will fail, whereas a ref to a dualvar can be modified. They are
> otherwise identical, as you can see with Devel::Peek.
At least for me, they're not. Dumping a false value results in
SV = PVNV(0x83c2188) at 0x83fb448
REFCNT = 1
FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK)
IV = 0
NV = 0
PV = 0x83fe968 ""\0
CUR = 0
LEN = 4
while a dualvar constructed in this kind yields
SV = PVMG(0x840fad8) at 0x8400868
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pPOK)
IV = 0
NV = 0
PV = 0x83d6618 ""\0
CUR = 0
LEN = 4
------------------------------
Date: Tue, 17 Sep 2013 10:10:46 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Return values of boolean operators
Message-Id: <87y56veru1.fsf@sable.mobileactivedefense.com>
Peter Makholm <peter@makholm.net> writes:
> tmcd@panix.com (Tim McDaniel) writes:
>
>> In article <87ob7tb5hw.fsf@vps1.hacking.dk>,
>> Peter Makholm <peter@makholm.net> wrote:
>>>See the perlop man page under the heading "Relational Operators".
>>
>> I'm afraid that's not so in the Perl 5.14.2 installation. That
>> section has only
>
> No, it seems to have been added in the documentation for 5.16:
>
> Perl operators that return true or false generally return values that
> can be safely used as numbers. For example, the relational operators
> in this section and the equality operators in the next one return 1
> for true and a special version of the defined empty string, "" , which
> counts as a zero but is exempt from warnings about improper numeric
> conversions, just as "0 but true" is.
The reason for this being that this 'special version of the defined
empty string' (how did the regretful lapse of implying that 'the
undefined value' is 'an empty string' instead of 'an undefined pointer'
creep in here?) is what results from converting an empty string to a
number. These "Type conversion detected !!1 Run for your life
lest the snark^WGosling will eat you !!2" are presumably latter-day
additions to the code performing type conversions.
------------------------------
Date: Tue, 17 Sep 2013 10:19:41 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Return values of boolean operators
Message-Id: <87pps7erf6.fsf@sable.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>These "Type conversion detected !!1 Run for your life
> lest the snark^WGosling will eat you !!2" are presumably latter-day
> additions to the code performing type conversions.
Demonstration of that (5.10.1):
[rw@sable]~#perl -w <<'TT'
$s = "";
$n = $s + 2;
$n = $s + 3;
TT
Argument "" isn't numeric in addition (+) at - line 2.
This warns only once because $s has already been converted when
executeing the second addition.
------------------------------
Date: Tue, 17 Sep 2013 15:21:22 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Return values of boolean operators
Message-Id: <245mga-lkg2.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
> > Quoth Peter Makholm <peter@makholm.net>:
> >> tmcd@panix.com (Tim McDaniel) writes:
> >>
> >> > OK, which man page is it that has documentation of the return values
> >> > of boolean operators? 1 and '', but I dimly recall that there's
> >> > something special about the particular '' returned for false, that it
> >> > avoids ... um, some kind of warning if ... something ...
> >>
> >> See the perlop man page under the heading "Relational Operators".
> >>
> >> Basically it returns a dualvar, not quite unlike what is returned by
> >>
> >> Scalar::Util::dualvar(0,"")
> >
> > Exactly the same, in fact, except for PL_sv_no (the internal name of the
> > standard 'false' value) being a readonly constant. That means that this
> >
> > my $x = \!1;
> > $$x = 1;
> >
> > will fail, whereas a ref to a dualvar can be modified. They are
> > otherwise identical, as you can see with Devel::Peek.
>
> At least for me, they're not. Dumping a false value results in
>
> SV = PVNV(0x83c2188) at 0x83fb448
> REFCNT = 1
> FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK)
> IV = 0
> NV = 0
> PV = 0x83fe968 ""\0
> CUR = 0
> LEN = 4
That's not PL_sv_no: sv_no is immortal, so it has a very high refcount,
and readonly. It's probably a copy of sv_no: it's got an empty string
part, and zero IV and NV parts.
> while a dualvar constructed in this kind yields
>
> SV = PVMG(0x840fad8) at 0x8400868
I've no idea how you got a PVMG out of dualvar, but I think you must
have assigned the result to a variable which had already been used for
something else. The normal return value of dualvar is a PVNV.
> REFCNT = 1
> FLAGS = (IOK,POK,pIOK,pPOK)
> IV = 0
> NV = 0
> PV = 0x83d6618 ""\0
> CUR = 0
> LEN = 4
This SV is otherwise identical to the one above: it isn't NOK yet, but
that's just because it hasn't been evaluated in a NV context. The
difference between IOK and NOK is not visible from Perl.
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4036
***************************************