Gu, Han wrote: > > Still very noob when it comes to perl. Just have a quick question. I am > trying to match a string that is window's path > > Sample, > > $s1 = "c:\\log\s1.log"; > > $s2 = $s1; > > If ($s1 =~ m/$s2/i) { > print "matched\n"; > } > > It just wouldn't match. I can put the actual string into m//i, which would > work, but I have to make it work with variable, since I'll be reading in the > actual string from a file. > > Greatly appreciate any answer I get.
First of all it is best to use single quotes when defining strings that contain backslashes. my $s1 = 'c:\log\s1.log'; then you don't need to escape them (unless one appears as the final character in the string, when you still need to double it up to avoid escaping the string terminator). The canonical way of doing a case-independent string comparison is to use 'eq' with the lower case (or upper case) version of both operands. So use strict; use warnings; my $s1 = 'c:\log\s1.log'; my $s2 = $s1; if (lc $s1 eq lc $s2) { print "matched\n"; } HTH, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/