This did it. I defined the hash and then did the key/value assignments like
this:

%arr_criteria_hash = ();

        sub ShowCriteria { #($theKey, $theValue, $theName) {
                $arr_criteria_hash{@_[0]} = @_[1];
...
        }
I did this so I can read it with a while loop. I didn't want blank keys if I
could help it.

So I have a nice, neat:
while (($field, $search) = each(%arr_criteria_hash))
        {
                $newText = " $field like '%$search%'";
...
        }
Without checking for decoys.
Thanks for the response. And thanks to John E.

However, in "if($vars{vNameL}) {" what does the $vars do? I have not seen
that.

-----Original Message-----
From: Brett W. McCoy [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 17, 2001 11:04 AM
To: Bradshaw, Brian
Cc: [EMAIL PROTECTED]
Subject: Re: hash assignment question


The way you are doing it, you are redefining your hash each time, not
adding new key/value pairs.  I would create hash first (outside your if
statements), and then add elements as you need them:

my %arr_criteria = ();

...

$arr_criteria{'last_name'} = $vNameL;

Perl will automatically create the hash element for you.

In fact, as far as organization goes, I would add the elements to the hash
initially, with sensible default values (even empty strings) and then test
to see if the hash element exists.  Are you using CGI.pm?  You can grab
ALL of the values from a form by using the Vars() function, which will put
everything nice and neat into a hash for you.  Then you can do:

if($vars{vNameL}) {

    # do stuff
}

And not even worry about adding the elements yourself.

-- Brett

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

Reply via email to