Solved

finding the match

Posted on 2000-03-21
8
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 84

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 84

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

635 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