Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

finding the match

Posted on 2000-03-21
8
Medium Priority
?
194 Views
Last Modified: 2010-03-05
This looks simple but it turned not as so for me.

I have a number $number = 12546;
I have another number $number1 = 2;

I need to do the following:

if ("$number1" =~ /"$number"/)
{do something}
else
{ do something else};

Which means that I need to treat two numbers as strings and execute the first condition only of the first number contains the same number as the second one.

Please help;
0
Comment
Question by:sstouk
  • 3
  • 3
  • 2
8 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 200 total points
ID: 2641909
if( $number =~ /$number1/ )
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2641918
I would do:
if (index($number,$number1) > -1)
  {do whatevere}
else
  {the other stuff}
0
 
LVL 6

Author Comment

by:sstouk
ID: 2641938
Ozo was first and his answer is more elegant. Perhaps the jhurst's answer would work as well but I tried ozo's and it worked perfectly with less typing.

So I really want to assign the points to him but thanks for the answer jhurst. It was fast and I appriciate it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 85

Expert Comment

by:ozo
ID: 2641942
What do you mean by "contains"?
0
 
LVL 6

Author Comment

by:sstouk
ID: 2641949
You helped me one more time. I am just learning Perl and I appriciate you answering me.

Thanks again.
0
 
LVL 6

Author Comment

by:sstouk
ID: 2641954
contains means "includes" or "has"
like  number "3462789" contains the "9" as a last number.

Thanks again.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2641967
I agree - ozo must have posted his answer while I was entering mine since his was not there when I entered mine but clearly got posted before mine.
0
 
LVL 85

Expert Comment

by:ozo
ID: 2641998
Ok, then it looks like jhurst and I interpreted your question as you intended.
It just occured to me after I wrote that answer that "contains the same number as" might also have been interpreted to mean "=="
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question