Dear Casey and the list,
Thanks for your all of your valuable help,
What is $|++ for?
#!/usr/local/bin/perl -w
use strict;
$|++;
while ( <DATA> ) {
chomp;
print( &validate( $_ ) ? 'valid entry' : 'try again punk' );
print "\n";
}
sub validate {
my $currency = shift;
# return false if we have an empty string or the string is just '$'.
return 0 unless length( $currency ) > 0 && $currency ne '$';
$currency =~ m<
^ # The beginning of the string
\$? # We may have a $ sign, we may not
\s* # We may encounter some space here
\d* # We may nave a numerator but could just have '.50'
(?:\.?\d{1,2})? # and we might have a denominator
$ # The end of the string
>x ? 1: 0; # true if match succeeded, false otherwise
}
-----------
sub checkPrice{
return ($_[0] !~ /^\$?(\d+|\d*\.\d\d)$/) ? 1 : 0;
}
Is there a shorthand? Or do I need $_[0],
---------
I could not seem to include the sub chekPrice in my if statement
$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'})
)
{ ......
-----------
Are there any issues with using
if (!length $in{price}) ....
as opposed to:
if ($in{price} eq "") ...
I am not sure about !length,
I mean it is not a $length, so it is not scalar is it some special variable?
Thanks to [EMAIL PROTECTED] (Paul Johnson) for his input on this.
--------
Dave