cei has asked for the wisdom of the Perl Monks concerning the following question:
I've got a form and I'd like to have some of the fields be required.
I'm using CGI.pm and maping all the form variables into a namespace called Beta.
I was going to try something like this:
When I thought, gee, a hash might be good for this. So I tried:($errorcodes .= "<li>First Name") if !($Beta::FirstName); ($errorcodes .= "<li>Last Name") if !($Beta::LastName); ($errorcodes .= "<li>Email Address") if !($Beta::Email);
I had to move out of the $Beta:: namespace, because it didn't like $Beta::$key.my ($key, $value); my %required = { FirstName => 'First Name', LastName => 'Last Name', Email => 'Email' }; while ( ($key, $value) = each %required) { ($errorcodes .= "<li>$value") if !($page->param("$key")); }
Anyway, I also traced $key = $value, and it's giving me HASH(0x1012b848) =
So obviously I'm getting references instead of values. But I'm new to hashes, and I'm not sure where to go from here.
Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple Hash Q.
by merlyn (Sage) on Nov 26, 2000 at 08:54 UTC | |
by cei (Monk) on Nov 26, 2000 at 09:06 UTC | |
by Fastolfe (Vicar) on Nov 26, 2000 at 09:14 UTC | |
by cei (Monk) on Nov 26, 2000 at 09:20 UTC | |
by Ovid (Cardinal) on Nov 26, 2000 at 19:10 UTC | |
|
Re: Simple Hash Q.
by extremely (Priest) on Nov 27, 2000 at 08:45 UTC | |
|
Re: Simple Hash Q.
by damian1301 (Curate) on Nov 27, 2000 at 03:06 UTC | |
by Fastolfe (Vicar) on Nov 27, 2000 at 04:05 UTC |