On Thu, 2006-06-04 at 22:29 +1000, Owen wrote:
> I would like to accept monetary values like
> 
> $234.00
> $2678
> 
> but not values with letters like
> 
> $333.oo
> 
> This script below almost works, but I can't get it to catch the $40o.89
> 
> Is there a simpler way to do this and catch all the conditions?
> 
> TIA
> 
> Owen
> 
> 
> #!/usr/bin/perl
> 
> while (<DATA>){
> chomp;
> $payment=$_;
> 
> unless (($payment =~ /\$[\d,]+\.\d{2}/)
> or ($payment =~ /\$[\d,]+/)

  or( $payment =~ /\$[\d,]+\b/ )

# \b is a word boundary, an alphanumeric character
# followed by a non-alphanumeric character
# or vice versa.

> and ($payment !~ /\$[\d,]+\.\D{2}/))
> {print "$payment seems to be an invalid amount\n";}
> 
> }
> __DATA__
> $122.30
> $40o.89
> $20
> $2222.oo
> 
-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to