Carlos C.Gonzalez wrote:

>Hi everyone,
>
>Given the following code why does it print out "Valid chars in string."?  
>In other words why does the space between "San" and "Jose" not make the 
>if expression true?
>
>my $string = "San Jose";
>
>if ($string !~ /[a-zA-Z]/) {
>  print "Invalid characters in string."
>}        
>else {
>  print "Valid chars in string."         
>}              
>
You are saying - "Report invalid characters unless there are 
alphabetical characters in the string".
But there are alphabetical characters in the string...
You shuld have said - "Report invalid characters unless there are ONLY 
alphabetical characters in the string, from the beginning to the and".

That is instead of:

if ($string !~ /[a-zA-Z]/) {

you should have written

if ($string !~ /\A[a-zA-Z]\Z/) {

(\A meaning beginning and \Z the end of the string).



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

Reply via email to