|There's more than one way to do things|
testing for the zero length string (blank value) in cgi fieldsby scratch (Sexton)
|on Oct 24, 2001 at 17:41 UTC ( #121104=perlquestion: print w/replies, xml )||Need Help??|
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:
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,
Back to Seekers of Perl Wisdom