David,
What I *think* you are asking is how to assign default values to form parameters and
then, after
reading all form values, have special handling of those parameters that have those
default values.
Your question is a bit vague (or maybe it's me?), so I'm just guessing. I'll respond
by first
listing how I handle assigning default values and then how I would loop through to
test for them
(essentially reversing the order of your email):
> ------------------what I want to replace------
>
> my $contact = param("cnt");
> if (not defined $contact) {$contact = ""; }
>
> my $phone = param("ph");
> if (not defined $phone) {$phone = ""; }
>
> my $address = param("adr");
> if (not defined $address) {$address = ""; }
>
> my $baths = param("bth");
> if (not defined $baths) {$baths = "0"; }
>
> my $stove = param("stv");
> if (not defined $stove) {$stove = "???"; }
I would code that section as follows:
my $contact = param("cnt") || "";
my $phone = param("ph") || "";
my $address = param("adr") || "";
my $baths = param("bth") || "0";
my $stove = param("stv") || "???";
> use CGI qw/:standard/;
>
> @fields = param(); # I think it returns a list of all the fields,
> # maybe we want to inslist a hash to get the values.
>
> foreach (@fields){
>
> if ( $_ ~= /(|\?+|\d)/ ) {
>
> # match "" or ??? or 0
> # do something .... blank field found!
> }
> }
Your regular expression is incorrect. Further, I wouldn't use it (at least, not given
the
defaults you have listed).
my @fields = param();
foreach my $field ( @fields ) {
if ( ! $field or $field eq '???' ) {
# we had a blank field
}
}
If you must use a regular expression:
foreach my $field ( @fields ) {
if ( $field =~ /^(?:|\?{3}|0)$/ ) {
print "Bad: '$field'\n";
} else {
print "Good: '$field'\n";
}
}
Cheers,
Curtis "Ovid" Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]