Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Checking for single digit

by vladb (Vicar)
on May 06, 2003 at 01:14 UTC ( #255780=note: print w/ replies, xml ) Need Help??


in reply to Checking for single digit

In your match try to use the special regexp anchors ^ and $:

if ($input =~ /^[0-9]$/) { print "input was a single digit number\n"; } else { print "input wasn't a single digit number\n"; }

From the Perl regular expression tutorial (perlre), the "^" and "$" are defined as:
^ Match the beginning of the line $ Match the end of the line (or before newline at the end)
Unless they are used, Perl will look for a match anywhere within your $input string! ;-)

Update: threw in some perldoc definitions for your viewing pleasure :)

_____________________
# Under Construction


Comment on Re: Checking for single digit
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (18)
As of 2015-07-28 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls