On Sun, Aug 05, 2001 at 09:44:00PM -0600, 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?
You are reversing the sense of the test with !~. It's effectively "!$string
=~ /[a-zA-Z]", meaning the test will only evaluate to true if there are no
[a-zA-Z] characters in the string. "San Jose" has 7 such characters.
If you are trying to verify the string has non-alphabetic characters, you
should say:
if ($string =~ /[^a-zA-Z]/) {
print "Invalid characters ..."
} else {
...
}
> my $string = "San Jose";
>
> if ($string !~ /[a-zA-Z]/) {
> print "Invalid characters in string."
> }
> else {
> print "Valid chars in string."
> }
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]