Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Some perl regex help

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


alex_v2 at yahoo

Jun 29, 2008, 9:47 PM

Post #1 of 4 (594 views)
Permalink
Some perl regex help

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;

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-tp18188634p18188634.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


js5 at sanger

Jun 30, 2008, 12:24 AM

Post #2 of 4 (563 views)
Permalink
Re: Some perl regex help [In reply to]

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-tp18188634p18188634.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.


alex_v2 at yahoo

Jun 30, 2008, 4:34 AM

Post #3 of 4 (558 views)
Permalink
Re: Some perl regex help [In reply to]

This worked great thanks. Was exactly what I was looking for.

-Alexander


James Smith-7 wrote:
>
>
>
> 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-tp18188634p18188634.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.
>
>

--
View this message in context: http://www.nabble.com/Some-perl-regex-help-tp18188634p18193673.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


perrin at elem

Jun 30, 2008, 5:52 AM

Post #4 of 4 (567 views)
Permalink
Re: Some perl regex help [In reply to]

On Mon, Jun 30, 2008 at 12:47 AM, Alexander Burrows <alex_v2[at]yahoo.com> wrote:
> 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.

This list is for mod_perl, not general Perl help. In the future, if
you need help with a regex please use one of the resources listed
here:
http://perl.apache.org/docs/offsite/other.html#Perl

The "beginners" mailing list is a good place to ask, and so is perlmonks.org.

- Perrin

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.