>   my $age = param('age') || 12;
>
> Is that an acceptable way of doing things, or is there some
> glaringly obvious mistake? It seems to pick up null and undefined
> values okay, without any errors (i.e. no age param, or age= will
> get 12). Only problem is that it treats 0 as null/undefined, but
> that's fine in a lot of cases.

It doesn't treat 0 as undefined, it merely treats it as false :-)

my $age = param("age") eq "0" ? 0 : param("age") || 12;

will probably do what you want (except that it will fail on "0.0"
etc), as long as you don't get any non-empty strings that can't be
converted to a number... The solution depends somewhat on what you
want to do in that case I guess.

Now there remains only one question: How many people will use your
program whose age is 0? :-)

        Elias

PS: Can't anyone come up with a nicer way to do this? Mine looks so
ugly...

-- 
"There are people who don't like capitalism, and there are people who don't like PCs,
but there's no one who likes the PC who doesn't like Microsoft."
 -- Bill Gates




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to