I thought it would be good to be able to do this:
$item = "";
$item =~ tr/<>/(<)(>)/;
to convert those <> symbols to their entity references.
however, the tr operator doesn't seem to like using () to group... any
comments on how to make this operation in to a one-liner?
Thanks
Mike
--
To u
$item =~ s//>/g;
Well. It is on one line ;)
John
-Original Message-
From: KAVANAGH, Michael [mailto:[EMAIL PROTECTED]]
Sent: 31 January 2002 14:06
To: '[EMAIL PROTECTED]'
Subject: html entity conversion... one liner?
I thought it would be good to be able to do
On Thu, 2002-01-31 at 09:06, KAVANAGH, Michael wrote:
> I thought it would be good to be able to do this:
>
> $item = "";
> $item =~ tr/<>/(<)(>)/;
>
> to convert those <> symbols to their entity references.
> however, the tr operator doesn't seem to like using () to group... any
> comments on
On Thu, 31 Jan 2002 14:06:06 -, Michael Kavanagh
<[EMAIL PROTECTED]> wrote:
> I thought it would be good to be able to do this:
>
> $item = "";
> $item =~ tr/<>/(<)(>)/;
>
> to convert those <> symbols to their entity references. however, the
> tr operator doesn't seem to like using () to g
(
'<' => '<',
'>' => '>',
'&' => '&',
);
$item = "";
$item =~ s/([<>&])/$entity{$1}/ge;
which isn't even a one liner as you have to define a lookup hash to b
Michael Kavanagh wrote:
>
> I thought it would be good to be able to do this:
>
> $item = "";
> $item =~ tr/<>/(<)(>)/;
tr/// will translate the '<' to a '(' and the '>' to a '&'.
> to convert those <> symbols to their entity references.
> however, the tr operator doesn't seem to like using (
ier to
extend than individual regexs if you are defining a lot of entities
(that is why my example had an & in it). Of course you should probably
not be doing any of this yourself; I am sure a module exists out there
to handle this sort of case.
>
> All IMHO ;)
>
> John
>
>
> -Original Message-
> From: KAVANAGH, Michael [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 31, 2002 9:06 AM
> To: '[EMAIL PROTECTED]'
> Subject: html entity conversion... one liner?
>
>
> I thought it would be good to be able to do thi
s not a one liner, but it does look nicer and is easier to
> extend than individual regexs if you are defining a lot of entities
> (that is why my example had an & in it). Of course you should probably
> not be doing any of this yourself; I am sure a module exists out there
> to