Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Check if a variable contains only one letter?

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


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

UPDATE: Nevermind... I misread the question. I thought the variable was of length 1. It would have helped had the OP shown any input at all.

Use eq instead of a regex:

use warnings; use strict; while (<DATA>) { chomp; print "ERROR $_\n" unless $_ eq 'X'; } __DATA__ X XA XB

Replies are listed 'Best First'.
Re^2: Check if a variable contains only one letter?
by LanX (Saint) on May 02, 2014 at 14:16 UTC
    > It would have helped had the OP shown any input at all.

    agreed, I also wasted time answering another question. :(

    > Check if a variable contains only one letter

    DB<106> $str='A B C' => "A B C" DB<107> @matches= $str=~/([A-Z])/g => ("A", "B", "C") DB<108> scalar @matches => 3

    DB<115> $str='A B C' => "A B C" DB<116> $str !~ /[A-Z].*[A-Z]/ => "" DB<117> $str=" A " => " A " DB<118> $str !~ /[A-Z].*[A-Z]/ => 1

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found