Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Check if a variable contains only one letter?

by Anonymous Monk
on May 02, 2014 at 14:36 UTC ( [id://1084795]=note: print w/replies, xml ) Need Help??


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

As evidenced by the varied responses from the other monks, your problem statement is somewhat unclear.

Perhaps this is what you're looking for?

#!/usr/bin/env perl use warnings; use strict; while (my $myvar=<DATA>) { chomp($myvar); if ($myvar=~/^([A-Z])\1*$/) { print "'$myvar' matches\n"; } else { print "'$myvar' doesn't match\n"; } } __DATA__ X XXXX XXXY XXYX YXXX AAAA BBBB BBBC DDD4

Output:

'X' matches 'XXXX' matches 'XXXY' doesn't match 'XXYX' doesn't match 'YXXX' doesn't match 'AAAA' matches 'BBBB' matches 'BBBC' doesn't match 'DDD4' doesn't match

Log In?
Username:
Password:

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

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

    No recent polls found