ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-mod_perl
perl-mod_perl
Re: Some perl regex help
by James Smith other posts by this author
Jun 30 2008 12:24AM messages near this date
Re: Some perl regex help | Re: Some perl regex help
On Sun, 29 Jun 2008, Alexander Burrows wrote:

> 
>  Hello again all. Been a while since I've posted here but needed some help on
>  a regex I was trying to write.
> 
>  $line =~ tr/(\(|\)|<|>)/(\&#40;|\&#41;|\&lt;|\&gt;)/g;

Simplest approach is to make a hash of the substitutions and use
an "e" executed regexp

my %hash = ('('=> '&#40;',')'=>'&#41;','<'=>'&lt;','>'=>'&gt;');

    $line =~ s/([()<> ])/$hash{$1}/eg;

> 
>  This does not work at all in perl so I found so I replaced the tr with s and
>  the search part works as expected but the replace does not. I've been trying
>  to read around forums and regex documents for perl but they seem unorganized
>  and cryptic. So any help would be appreciated.
> 
>  -Alexander
>  -- 
>  View this message in context: http://www.nabble.com/Some-perl-regex-help-tp18188634p181886
34.html
>  Sent from the mod_perl - General mailing list archive at Nabble.com.
> 
> 


-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 
Thread:
Alexander Burrows
Perrin Harkins
James Smith
Alexander Burrows

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved