On Tue, 26 Aug 2003 14:23:07 +1000, Anthony English wrote:
>      # make sure year is at least 2 but not more # than 4 digits
>       if ($year =~ /\d{2,4}/) {                            
Hello Anthony,

        it is clear while your regex does match numbers bigger than 4 characters. 
There isn't a minimum set for the maximum value. You are testing for 4 digits. This is 
true even if there are 5, 6 or even 7 digits.

        In your case you just need to put boundaries up and everything is fine:

---+++---
#!/usr/bin/perl

use warnings;
use diagnostics;
use strict;

print "What year? ";                                     
chomp (my $year = <>);                                                
                                    
if ($year =~ /^\d{2,4}$/) 
{                            
        print "year is between 2 and 4 digits\n";        
} 
else 
{                                             
        print "Error: year should be between 2 and 4 digits.\n";
}
---+++---

^ symbolizes the beginning of a string.
$ symbolizes the end of a string.

thanks
/oliver/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to