The way you're using regex's won't get you what you want.
/[a-z]+/i will match a string with one or more upper and lower case letters (in a weird way, but it works) but there's lots of other characters in the world than just A-Z and "numbers." If $a="%_!@" your code will proudly proclaim that $a is "numeric" which it isn't, at least for my definition of numeric. :-D
If what you want to do is distinguish between letters and numbers, you might try:
#!/usr/bin/perl -w
my $a = "aBcdeFG";
if ($a =~ /[A-Za-z]/) { # No i modifier needed
print "Alphabet\n";
}
elsif ($a =~ /\d/) { # \d matches 0-9 only
print "Numeric\n";
}
else {
print "Non-numeric, non-alphabet\n";
}
Gary Blackburn
Trained Killer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.