Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: vallidating a regular expression

by reasonablekeith (Deacon)
on May 11, 2006 at 09:07 UTC ( [id://548643]=note: print w/replies, xml ) Need Help??


in reply to vallidating a regular expression

Your question is a perfect example of why you should provide a working example when asking questions on SOPW

I'm assuming you're doing something like this...

my @test_numbers = qw(1 2 5 8 10 12 14 56); foreach my $test_number (@test_numbers) { if( $test_number =~ /^\d{2}$/){ if($test_number <= 10){ print "$test_number\n"; } } }
If that assumption is correct, then as already mentioned, your single digit numbers are not passing your regex because you've mandated that there must be two characters.

this is a simple fix to the regex, combined with getting rid of your nested if statement you get the following.

foreach my $test_number (@test_numbers) { if( $test_number =~ /^\d{1,2}$/ and $test_number <= 10){ print "$test_number\n"; } } __OUTPUT__ 1 2 5 8 10
but without knowing exactly what your data was, it's hard to say if this is right for you.
---
my name's not Keith, and I'm not reasonable.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found