Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Answer: How do I match a number range?

by quidity (Pilgrim)
on Nov 28, 2000 at 06:14 UTC ( [id://43595]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I match a number range?
in thread How do I match a number range?

> my $range = join '|', 5278..5391; > my $number = 5300; > print "Matched\n" if $range =~ /\b$number\b/;

You want $number =~ /^($range)$/ instead.

Also, you need to create a potentially large list in memory then turn it into a large string. For numbers of this size, this isn't really a problem, but what if you are trying to match unix time values, that's 780k just to match a one day time frame.

Replies are listed 'Best First'.
(tye)Re: Answer: How do I match a number range?
by tye (Sage) on Nov 28, 2000 at 22:54 UTC

    I disagree. If you wanted to see if a number fell within a certain range, then a regex would be a really bad tool to use. However, if you wanted to match all occurances within some larger string of numbers that fell within a certain range, then the pain of using a regex to match a number range might pay off. So I think the original answer was closer to correct than yours. But I think mine is even closer:

    /(^|\D)($range)(\D|$)/
    since the original doesn't find the number in "x5300x".

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

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

    No recent polls found