On Thu, 2008-12-18 at 10:42 -0500, Gu, Han wrote: > Hi, > 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. > > Thx > > Han
To match non-alphanumeric characters in a string, you need to quotemeta it. if( $s1 =~ m/\Q$s2\E/i ){ # ... Or my $s2 = quotemeta( $s1 ); if( $s1 =~ m/$s2/i ){ # ... See: perldoc quotemeta perldoc perlretut perldoc prelre -- Just my 0.00000002 million dollars worth, Shawn The key to success is being too stupid to realize you can fail. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/