Archive of UserLand's first discussion group, started October 5, 1998.

Re: Is XML-RPC a scripting environment?

Author:Emmanuel M. Décarie
Posted:1/20/1999; 6:56:55 AM
Topic:Frontier on MacOS X Server
Msg #:2296 (In response to 2293)
Prev/Next:2295 / 2297

Perl must have *some* convention for what a boolean is, right? How could you program without booleans?

Dave, in some ways, and I hope I'm not misleading you, in Perl, all scalars are strings, but depending of the context, they get converted in other datatypes (integer, boolean...). If you want to get a quick overview of Perl, I suggest Perl in a Nutshell from O'Reilly. This book cover all aspects of Perl in an encyclopedic way.

From Programming Perl (2nd edition, p. 21) [BTW I find the first paragraph very interesting in the context of the political situation in the US]:

Basically, Perl holds truths to be self-evident. That's a glib way of saying that you can evaluate almost anything for its truth value. Perl uses practical definitions of truth that depend on the type of thing you're evaluating. As it happens, there are many more kinds of truth than there are of nontruth.

Truth in Perl is always evaluated in a a scalar context. (Other than that, no type coercion in done.) So here are the rules for the various kinds of values that a scalar can hold:

  1. Any string is true except for "" and "0".
  2. Any number is true except for 0.
  3. Any reference is true.
  4. Any undefined value is false.

(...)

0           # would become the string "0" so false
1           # would become the string "1", so true
10 - 10     # 10 - 10 is 0, would convert to string "0", so false
0.00        # becomes 0, would convert to string "0", so false
"0"         # the string "0", so false
""          # a null string, so false
"0.00"      # the string "0.00", neither empty nor exactly "0", so true
"0.00" + 0  # the number 0 (coerced by the +), so false
$a         # a reference to $a, so true, even if $a is false
undef()     # a function returning the undefined value, so false

Cheers

-- Emmanuel (dreaming of a Frontier in a Nutshell book)




This page was archived on 6/13/2001; 4:47:25 PM.

© Copyright 1998-2001 UserLand Software, Inc.