Another question since I hit another snag on this, hopefully it's the last =)
Sample -->
$s2 = "c:\ise\conf\ise_eif_lvc.config";
$s1 = <STDIN>; # This could be from command line or reading from a file
# But the input will be the following --
#<add key="instrumentationConfig" value="c:\ise\conf\ise_eif_lvc.config" />
if( $s1 =~ m/\Q$s2\E/i ){
print "matched\n";
}
Somehow this would work, and seems to be the double-quote in the input that's
causing the issue. I've tried the quotemeta on $s1, but that didn't help.
Although if I put the actual string into $s1 and use \ to escape the ", then it
would work. I thought quotemeta does just that.
Again, many thx in advance.
Han
-----Original Message-----
From: Mr. Shawn H. Corey [mailto:[email protected]]
Sent: Thursday, December 18, 2008 10:51 AM
To: Gu, Han
Cc: '[email protected]'
Subject: Re: Trying to match window's path
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: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/