----- Original Message -----
From: Paul Johnson <[EMAIL PROTECTED]>
To: David Gilden <[EMAIL PROTECTED]>
Cc: Casey West <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, April 23, 2001 10:30 PM
Subject: Re: quick PERL question
> >
> > $x = &checkPrice($in{'price'});
> > if ( ($in{'name'} eq "") or
> > ($in{'type'} eq "") or
> > ($in{'price'} eq "") or
> > $x)
> >
> > { .....
> >
> >
> > ### won't pass syntax validation!
> > if ( ($in{'name'} eq "") or
> > ($in{'type'} eq "") or
> > ($in{'price'} eq "") or
> > &checkPrice($in{'price'})
> > )
> >
> > { ......
>
> Hmmm. Looks OK. You'll have to be a bit more explicit unless someone
> else can see the problem.
Dont see a problem.
Personally i would move the checks for empty price strings to the
checkprice() sub.
No use checking it tho, cuz if it is of zero length it will never match.
Following works though:
( length($in{'type'}) && length($in{'name'}) && checkprice($in{price}) )||
print "Your input sux\n";
sub checkprice{
return if !length($_[0]) # avoid warnings on match on undef value
return ($_[0] =~ /^\$?(\d+|\d*\.\d\d)$/) ;
}
or if you want to give information about the missing field:
foreach ( ('type', 'name') ){
length $in{$_} or print "Missing input: $_\n";
}
checkprice($in{price}) || print "Invalid price entered\n";
--------
maarten.