Solved

finding the match

Posted on 2000-03-21
8
165 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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