mhearse has asked for the wisdom of the Perl Monks concerning the following question:
Then in the callin script:sub get_my_params { my @array; $array[0] = defined (param('ticket')) ? param('ticket') : ""; $array[1] = defined (param('title')) ? param('title') : ""; $array[2] = defined (param('client')) ? param('client') : ""; $array[3] = defined (param('next_step')) ? param('next_step') : " +"; $array[4] = defined (param('o_date')) ? param('o_date') : ""; $array[5] = defined (param('o_time')) ? param('o_time') : ""; return @array; }
During the script I want to evaluate some of the variables. They evaluate for truth correctly:require "tickets.pm"; my ($ticket, $title, $client, $next_step, $o_date, $o_time) = get_my_p +arams();
But if I tryif ($title) {}
I always get a match, even if no parameter was passed. An empty "" isn't defined, is it? When declaring empty variables, should I use undef instead of ""?if (defined ($title)) {}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scalar evaluation
by Joost (Canon) on Mar 06, 2005 at 21:54 UTC | |
|
Re: Scalar evaluation
by phroggy (Monk) on Mar 06, 2005 at 23:47 UTC | |
by ysth (Canon) on Mar 07, 2005 at 00:56 UTC | |
|
Re: Scalar evaluation
by dragonchild (Archbishop) on Mar 07, 2005 at 13:31 UTC |