On 2007-06-29 16:57:55 -0700, Bill Moseley wrote: > On Fri, Jun 29, 2007 at 03:03:42PM -0500, CAMPBELL, BRIAN D (BRIAN) wrote: > > Then if you want all chars to be treated literally, then I presume you > > want: > > \% > > To be translated to: > > \\\% > > So just adding your $esc to the left part of s/// should do the trick, > > right? > > The \\% is translated to: > > \\\\% > > Which leaves the % unescaped.
Nope:
#!/usr/bin/perl
use warnings;
use strict;
my $esc = '\\';
for my $s ('%', '\\%', '\\\\%') {
my $search_pattern = $s;
print "$search_pattern -> ";
$search_pattern =~ s/([\Q$esc\E_%])/$esc$1/g;
print "$search_pattern\n";
}
prints:
% -> \%
\% -> \\\%
\\% -> \\\\\%
which is as it should be.
hp
--
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | [EMAIL PROTECTED] | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
pgp49tDIxIwdy.pgp
Description: PGP signature
