Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Partial String Match 1

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA

I have an easy question. I want to compare two strings to see if they are partially matching

My code:

Code:
$string = A4522-ITRZ;
$search_string = "A4522";

if ($string =~ /$search_string/) {
    print "$string";
}

The current code doesn't work ? Can anyone tell me why.

Thanks
 
You didnt have speech marks for $string value
... and use strict!!!

This works...

Code:
use strict;

my $string = "A4522-ITRZ";
my $search_string = "A4522";

if ($string =~ /$search_string/) {
    print "Woohoo!";
}

[2thumbsup]
 
speech marks", otherwise known as double-quotes.

Simple strings with no interpolation should really just use single-quotes though.

Numbers need not be quoted at all.
 

I was using double quotes in my code but I simply used the $string and $search_string as an example and I forgot to put the double quotes there. I found out that I forgot the /i to make it not case sensitive. My example was bad because it was in upper cases.

Thank you anyways..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top