Hi Experts,
I am having trouble in matching a string containing question marks.
Below is my code:
Below is the source file 'cc':
Below is the test run:
How do I let all the five strings match themselves? Especially, the first line in the source file 'cc' is derived from a live dataset in real world. I need to use it to match the records in another file. Because it contains '?', the match always returns FALSE.
what should I do? any advices?
thanks!!!
I am having trouble in matching a string containing question marks.
Below is my code:
Code:
# Read from a file and assign $str1, $str2, & $str3
my $f = 'cc';
open(H, $f);
my @tmp = <H>;
close(H);
my $str1 = $tmp[0];
chomp($str1);
my $str2 = $tmp[1];
chomp($str2);
my $str3 = $tmp[2];
chomp($str3);
# Assign two more -- $str4 && $str5
my $str4 = qq/4_seg\\?ids/;
my $str5 = qq/5_seg_ids/;
print "\$str1 = $str1\n";
print "\$str2 = $str2\n";
print "\$str3 = $str3\n";
print "\$str4 = $str4\n";
print "\$str5 = $str5\n";
if($str1 =~ /$str1/) {
print "==>> String 1 matches itself!! $str1\n";
}
else {
print "==>> String 1 does not match itself!! $str1\n";
}
if($str2 =~ /$str2/) {
print "==-->> String 2 matches itself!! $str2\n";
}
else {
print "=->> String 2 does not match itself!! $str2\n";
}
if($str3 =~ /$str3/) {
print "---> String 3 matches itself!! $str3\n";
}
else {
print "---> String 3 does not match itself!! $str3\n";
}
if($str4 =~ /$str4/) {
print "#### String 4 matches itself!! $str4\n";
}
else {
print "#### String 4 does not match itself!! $str4\n";
}
if($str5 =~ /$str5/) {
print "!!!! String 5 matches itself!! $str5\n";
}
else {
print "!!!! String 5 does not match itself!! $str5\n";
}
Below is the source file 'cc':
Code:
% cat cc
1_seg?ids
2_seg\?ids
3_seg\\?ids
Below is the test run:
Code:
% ./strMatch.pl
$str1 = 1_seg?ids
$str2 = 2_seg\?ids
$str3 = 3_seg\\?ids
$str4 = 4_seg\?ids
$str5 = 5_seg_ids
==>> String 1 does not match itself!! 1_seg?ids
=->> String 2 does not match itself!! 2_seg\?ids
---> String 3 does not match itself!! 3_seg\\?ids
#### String 4 does not match itself!! 4_seg\?ids
!!!! String 5 matches itself!! 5_seg_ids
How do I let all the five strings match themselves? Especially, the first line in the source file 'cc' is derived from a live dataset in real world. I need to use it to match the records in another file. Because it contains '?', the match always returns FALSE.
what should I do? any advices?
thanks!!!