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;

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to Passing undefined values to package by bradcathey

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.