SPUG: 0E0 Re: "Boolean" return values

DeRykus, Charles E charles.e.derykus at boeing.com
Tue Oct 14 08:56:57 PDT 2008


 


> Indeed, '0E0' (scientific exponent notation floating point) evaluates
to zero... but is not false.

> You can argue about the sense or ideosyncracy of this (is sense always
orderly and composed, and does ideosyncratic
>  == > nonsense? ahh philosophy!) but it is put to practical use.

> When you use DBI->connect()->do() the number of records affected is
returned as the function value if the operation 
> succeeds... otherwise the return value tests false. When zero records
are affected (but the operation was deemed
> successful) '0E0' is returned so that sense is preserved and the
operation doesn't return false.

> Does DBI have its lipstick on straight, or is trying to enforce strict
type checking on built-in types lipstick on 
> a pig? Does it matter to the pig (other than to annoy it, what with
all the fussing about), or is it solely something 
> done for the beholder?

Perl even provides its own  "lipstick for a pig" in the spirit of '0E0':


$ perl -wle 'print "true" if "0 but true"'
true

$ perl -wle 'print "0 but true" + 1'
1


>From 'perldoc -f fcntl':

  You don't have to check for "defined" on the return
  from "fnctl".  Like "ioctl", it maps a "0" return
  from the system call into ""0 but true"" in Perl.
  This string is true in boolean context and "0" in
  numeric context.  It is also exempt from the normal
  -w warnings on improper numeric conversions.


-- 
Charles DeRykus





More information about the spug-list mailing list