Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Reg Expression Question

by pix (Novice)
on Aug 31, 2001 at 13:44 UTC ( [id://109336]=note: print w/replies, xml ) Need Help??


in reply to Reg Expression Question

you could do something like that:

$okvalues = "0 20 34 23 5"; for($i = 1; $i < 100; $i++) { if($okvalues =~ m/$i/) { print "$i\n"; } }

Federico

Replies are listed 'Best First'.
Re: Re: Reg Expression Question
by blakem (Monsignor) on Aug 31, 2001 at 14:01 UTC
    Did you try the code you suggested above? For output I get:

    2 3 4 5 20 23 34
    It incorrectly matches on 2,3 and 4. Now if you had modified your regex to be:
    $okvalues =~ m/\b$i\b/
    You wouldn't have that problem, because the \b assertion is only true between a word char and a non wordchar. This stops '3' from matching on '34'. Though, its still not a good idea to do it this way.

    -Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-29 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found