Solved

finding the match

Posted on 2000-03-21
8
144 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
Comment Utility
if( $number =~ /$number1/ )
0
 
LVL 8

Expert Comment

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

Author Comment

by:sstouk
Comment Utility
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
 
LVL 84

Expert Comment

by:ozo
Comment Utility
What do you mean by "contains"?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 6

Author Comment

by:sstouk
Comment Utility
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
Comment Utility
contains means "includes" or "has"
like  number "3462789" contains the "9" as a last number.

Thanks again.
0
 
LVL 8

Expert Comment

by:jhurst
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now