develooper Front page | perl.perl5.porters | Postings from July 2010

Re: [perl #76756] PATCH: srand returns the seed

Thread Previous | Thread Next
From:
Chas. Owens
Date:
July 28, 2010 08:22
Subject:
Re: [perl #76756] PATCH: srand returns the seed
Message ID:
AANLkTi=2Qjxvbwh8Dim0s6HOZZC403q-h9X9A1uZ+zyP@mail.gmail.com
On Wed, Jul 28, 2010 at 10:33, demerphq <demerphq@gmail.com> wrote:
snip
>> "0 but true", "0e0", "0.0", and a couple other strings are true values
>> (because they aren't the string "0"), but don't elicit the 'Argument
>> "%s" isn't numeric%s' warning.
>>
>> perl -wE 'say $_ + 1, $_ ? " true" : " false" for qw/ 0 0.0 0e0 /, "0
>> but true", "0 but dkfjnkerfnk"'
>>
>> 1 false
>> 1 true
>> 1 true
>> 1 true
>> Argument "0 but dkfjnkerfnk" isn't numeric in addition (+) at -e line 1.
>> 1 true
>
> In particular 0E0 and variants are well known amongst people that use
> DBI, as DBI uses it for the "updated 0 rows, but no error occured".
>
> so you see stuff like
>
> my $rows= $dbh->do("update Foo set blah=?",undef,$var)
>  or die "Cant update Foo: ",$dbh->errstr();
> print "Updated ", 0+$rows, " rows\n";
>
> very regularly...
>
> yves
> --
> perl -Mre=debug -e "/just|another|perl|hacker/"
>

I took a [quick look][0] to see how well documented "0 but true" is.
It looks like it is only mentioned tangentially. Similarly, "0E0" gets
mentioned once in perlop:

   The final sequence number in a range has the string "E0" appended to it,
   which doesn't affect its numeric value, but gives you something to search
   for if you want to exclude the endpoint.

They should probably be documented in the [Truth and Falsehood][1]
section of perlsyn.  A patch will be forthcoming.  Does anybody know
the full list of strings that are not warned about?  I know that
strings that match the following regex are all true but do not warn in
numeric context:

my $zero_but_true = qr{
	\A
	\s*
	(?:
		0 but true        | # "0 but true"
		00+               | # "00", "000", etc.
		0+[.]0*           | # "0.", "00.00", etc.
		[.]0+             | # ".0", ".0000", etc.
		0+[eE][0-9]+      | # "0e0", "00e19", etc.
		0+[.]0*[eE][0-9]+ | # "0.e0", "000.000E19", etc.
		[.]0+[eE][0-9]+     # ".0e0", ".000e500", etc.
	)
        \s*
	\z
}x;

 [0]: http://www.google.com/search?q=+site:perldoc.perl.org+%220+but+true%22
 [1]: http://perldoc.perl.org/perlsyn.html#Truth-and-Falsehood

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About