in reply to Re: What is the correct definition of False and Null in Perl?
in thread What is the correct definition of False and Null in Perl?
(1) In Perl, the string: "0 but true" is an exception. This string will evaluate to a numeric 0, but a logical true! The logical "true" is not surprising, but the numeric 0 is! That is because this is a special case coded into Perl. Even under use strict; use warnings;, "0 but true" can be used in a numeric expression/computation.
(2) There is a more "modern way" of returning the "0 but true" value. That is the string "0E0". The DBI will return this to mean: "hey, I worked!, but I modified zero rows". 10**0 is one. So 0*10**0=0*1=0. So this enables the conveyance of (a)I worked (no error) and (b)result is zero within a single string value "0E0".#!/usr/bin/perl -w use strict; my $x = "0 but true"; print $x + 1; #prints 1!!! my $xx = "1 but true"; # print $xx +1; #Ooops ERROR! #non-numeric addition!
I have not seen recent code with the case (1) above. But I have verified that it does indeed work. You don't have to get too far into the DBI before you encounter (2) like when you are updating a table - the table update was just fine "true", but it just didn't do anything (rows modified = 0).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: What is the correct definition of False and Null in Perl?
by LanX (Saint) on Oct 08, 2011 at 17:12 UTC | |
by Marshall (Canon) on Oct 08, 2011 at 18:40 UTC | |
by LanX (Saint) on Oct 08, 2011 at 18:52 UTC | |
by Marshall (Canon) on Oct 27, 2011 at 02:24 UTC |