Solved

finding the match

Posted on 2000-03-21
8
178 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Syslog text file into database or into .CSV 19 196
use google analytics code in perl script 2 102
Perl Awk Need Help 3 150
Put query string from URL request -  PERL HTTP Daemon 2 102
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…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

752 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