[Perth-pm] Using \L and \E inside a variable, inside a substitution s///

James Bromberger james at rcpt.to
Sun Oct 24 09:39:49 PDT 2010


Hi all,

I'm trying to to a substitution on a URL to lower-case the the protocol
and host name in one regex, using variables for either side of the
substitution:
my $url = 'http://www.FOo.COm/wibbLE';
my $search = '^([^:]+://[^/]+)/?(.*)?$';
my $replace = '\L$1\E/$2';
print $url if $url =~ /$search/$replace/;

Sadly, the result is the literal "*\L$1\E/$2*".

Limitation is that I don't want to use eval() (also known as /e, and
/ee), as I don't trust the content of $replace - fine if it doesn't
nicely do a replace, bad if the eval() does a call to unlink and
friends. (Of course, with using eval the $replace could contain '*lc($1)
. "/$2"*'.)

Any ideas?
  James

-- 
*James Bromberger*
Aus Mobile: +61 422 166 708
Email: james /_AT_/ rcpt.to, Web: www.james.rcpt.to
<http://www.james.rcpt.to/>
MSN: james/_AT_/rcpt.to, AIM: JamesEBromberger, Skype: james.bromberger
(/_AT_/ -> @)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/perth-pm/attachments/20101025/3b1f048d/attachment.html>


More information about the Perth-pm mailing list