An amateur question regarding the evaluation of scalars. I have a shared routine which gets CGI params like so:
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; }
Then in the callin script:
require "tickets.pm"; my ($ticket, $title, $client, $next_step, $o_date, $o_time) = get_my_p +arams();
During the script I want to evaluate some of the variables. They evaluate for truth correctly:
if ($title) {}
But if I try
if (defined ($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 ""?

In reply to Scalar evaluation by mhearse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.