Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Check if a variable contains only one letter?

by choroba (Cardinal)
on May 02, 2014 at 14:05 UTC ( [id://1084789]=note: print w/replies, xml ) Need Help??


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

You should say "it contains X from the beginning to the end":
$myvar =~ /^X+$/;

Update: Be careful as "XXXX\n" also matches, so you might need to chomp first.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Check if a variable contains only one letter?
by tobyink (Canon) on May 02, 2014 at 22:59 UTC

    Regarding your update, just use /\AX+\z/.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^2: Check if a variable contains only one letter?
by DrHyde (Prior) on May 06, 2014 at 10:38 UTC

    Or if you don't know what the letter is ...

    if($myvar =~ /^([A-Za-z])\1*$/) { ... }

    That is, match the beginning of the string, then any letter, then any more of that same letter, then the end of the string. Adapt as appropriate for Unicode abominations.

Log In?
Username:
Password:

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

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

    No recent polls found