Hello all,

I'm using CGI.pm to collect some user info through a series of web pages. I've been just writing the captured data out to a file, but now I'm trying to write to a database. For the most part this is working well, but for a few fields I'm trying to test for a value of 'blank' or 'no data' (this would be for fields left unanswered). By default perl seems to convert these to a value of 0, but I'd like to convert them to -1.

My problem is in testing for this blank value. I've tried lots of things, all of them more or less like this:

@negs = qw ( foo bar baz ); foreach $neg (@negs) { if (param('$neg') eq "") { param(-name=>"$neg", -value=>-1) ; } }

This, however, replaces *all* values of foo, bar, and baz with -1, not just the blank values.

Is there a way I can test for the blank value? Is there a better way to achieve my goal of not allowing fields to be left blank by users, but recording a value of -1 in the database for these fields?

Thanks as always,

scratch


In reply to testing for the zero length string (blank value) in cgi fields by scratch

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.