Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!rbj From: rbj@uunet.UU.NET (Root Boy Jim) Newsgroups: comp.lang.perl Subject: Re: Comparing numbers and regular expressions Message-ID: <120866@uunet.UU.NET> Date: 2 Feb 91 02:31:27 GMT References: <5152@s3.ireq.hydro.qc.ca> Organization: UUNET Communications Services, Falls Church, VA Lines: 26 In<5152@s3.ireq.hydro.qc.ca>gamin@ireq-robot.hydro.qc.ca (Martin Boyer) writes: >$uid_list = "13|1"; >$this_uid = 101; >if ($this_uid =~ /^$uid_list$/o) { > print "Matches!\n"; >} else { > print "Doesn't match.\n"; >} > >This section prints Matches!, but that's not what I want; what I want >is for the test to succeed only for values of 13 or 1. You fell into an age old regular expression trap. You just compiled the pattern "^13|1$", which matches 13 at BOL or 1 at EOL. It has nothing to do with numbers, as substitution will show you. You need to compile /^($uid_list)$/o, or put each list member explicitly between ^ and $. >Can anybody enlighten me? No, but at least I can fix your perl problem for you. -- Root Boy Jim Cottrell Close the gap of the dark year in between