Re: Perl regex question



On Jan 21, 12:17 pm, James <hslee...@xxxxxxxxx> wrote:
$ cat subst.pl
%replace = ('<' => '<', '>' => '>', '\s+' => '<td>');
s/(<|>|\s+)/$replace{$1}/g;

$ echo "< hello >" | perl -n ./subst.pl
(there's a space between < and hello)

I am trying to get
<<td>hello<td>>

but I got
<hello>

How do I get it right?

James

Opps, the HTML entities got translated.
Is there a vanilla mode in posting?
Let me re-phrase the question again.

$ cat subst.pl
%replace = ('<' => '\&lt;', '>' => '\&gt;', '\s+' => '<td>');
s/(<|>|\s+)/$replace{$1}/g;

$ echo "< hello >" | perl -n ./subst.pl
(there's a space between < and hello)

I am trying to get
\&lt;<td>hello<td>\&gt;

but I got
\&lt;<hello>\&gt;

How do I get it right?

James
.



Relevant Pages