bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
I'm using a validation package to determine a number of things, in this case whether a radio button in a form has been clicked on.
Fundamentally, my problem comes when passing values to the package. If param('method') has a value, there is no problem—all the values are passed in proper order. However, if 'method' has no value, the flag '1' I'm using to indicate that the selection of a 'method' is mandatory is moved the to $value position in my package and a true value is erroneously returned.
If use quotes: "$query->param('method')" the $value in the package is CGI=HASH(0x811b24c)->param('method') and basically get no measurable result.
So, how do I make sure that the package "sees" the undefined value? The stop-gap would be to reverse the order Validate->checked (1, $query->param('method')), but that doesn't seem like a long-term solution.
Thanks!
use Validate; my ($method, $error) = Validate->checked ($query->param('method'), 1); if ( $error->{ msg } ) { push @errors, "A <b>method</b> $error->{ msg +}" } package Validate; sub checked { my ($class, $value, $mandatory) = @_; print Dumper ($class, $value, $mandatory); if (!$value && $mandatory) { return (undef, { msg => 'must be checked' }); } else { return ($value); } } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing undefined values to package
by tlm (Prior) on Aug 04, 2005 at 13:28 UTC | |
by bradcathey (Prior) on Aug 04, 2005 at 13:43 UTC | |
|
Re: Passing undefined values to package
by JediWizard (Deacon) on Aug 04, 2005 at 13:18 UTC |