Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Check if a variable contains only one letter?

by Yary (Pilgrim)
on May 02, 2014 at 15:56 UTC ( [id://1084803]=note: print w/replies, xml ) Need Help??


in reply to Check if a variable contains only one letter?

(edit) I have to now agree with the other posters, that my interpretation of the question is just one of many. The below is a simple answer to one of those interpretations.

I can't believe everyone's missed the obvious!

$myvar =~ /X/i && $myvar !~ /[A-WYZ]/i

If you want to try putting it all in one regexp, see this meditation- Matching and nonmatching multiple regexps at once

And if you want it to be Unicode-safe, not just matching ASCII- I'm sure it can be and should be done, but I'm not the one to ask...

(edit #2) And if you really want to know if a string is a single letter X then don't use regexp. $myvar eq 'X'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1084803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found