I do have a question though, why does that work, since it is not !~ and is =~?It reads more or less "it's true if the string contains (=~) something other (^) than letters and numbers (a-zA-Z0-9)", so it works.
You can of course use !~ as well, to say "it's true if the string doesn't contains (!~) one or more letters and numbers ([a-zA-Z0-9]+) in its entirety (hence the ^ and $ that constitutes the start and end marks).
which I prefer to write (yes back to =~ and not !~):print "bad string: $string\n" if $string !~ /^[a-zA-Z0-9]+$/;
print "bad string: $string\n" unless $string =~ /^[a-zA-Z0-9]+$/;
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
In reply to Re^3: check if string contains anything other than alphanumeric
by naikonta
in thread check if string contains anything other than alphanumeric
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |