scratch has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: testing for the zero length string (blank value) in cgi fields
by Masem (Monsignor) on Oct 24, 2001 at 17:49 UTC | |
Re: testing for the zero length string (blank value) in cgi fields
by davorg (Chancellor) on Oct 24, 2001 at 18:35 UTC | |
by blakem (Monsignor) on Oct 25, 2001 at 00:08 UTC | |
Re: testing for the zero length string (blank value) in cgi fields
by jj808 (Hermit) on Oct 24, 2001 at 17:52 UTC | |
Re: testing for the zero length string (blank value) in cgi fields
by tommyw (Hermit) on Oct 24, 2001 at 17:52 UTC |