[Perl] Problem in string comparison

Status
Not open for further replies.

maulin sheth

Advanced Member level 2
Joined
Oct 24, 2010
Messages
502
Helped
90
Reputation
179
Reaction score
90
Trophy points
1,318
Location
Bangalore, India
Visit site
Activity points
4,161
Hello All,

I have a text file like :
"IN" = IN_0[0..3]+IN_1[5...7];
"OUT" = OUT_0[2..5] + OUT_1;

Now I am trying the grep IN_1[5..7] but I am not able to grep only IN_1[5..7] string..
Script is like :

$pattern = "IN_1[5..7]";
for(@full_test_file)
{
if($file[$i] =~ m/$pattern/)
{
print "matched";
}
}

The main problem is it matches only IN_1 not IN_1[5..7],
I want solution rather than doing this: $pattern = 'IN_1\[5\.\.7\]'

Any other solution?

BR,
Maulin Sheth
 

to escape meta characters:
if($file[$i] =~ m/\Q$pattern\E/)
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…