RE: html entity conversion... one liner?
Just because tmtowtdi (even if it is not very efficient): $item = join '', map { s//lt;/ or s//gt;/; $_ } split //, $item; On Thu, 2002-01-31 at 09:51, Chas Owens wrote: On Thu, 2002-01-31 at 09:39, John Edwards wrote: Why *must* it be a one liner. I think my suggestion is easier to understand for someone having to maintain your code. If there is no other reason than I want a one liner to do this on one line, then why not do it on two?? Just because it is possible in one line, doesn't mean it's the best approach. To me this: $item = blah; $item =~ s//lt;/g; $item =~ s//gt;/g; Seems far easier to understand than either this: $item = blah; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; or this: my %entity = ( '' = 'lt;', '' = 'gt;', '' = 'amp;', ); $item = blah; $item =~ s/([])/$entity{$1}/ge; which isn't even a one liner as you have to define a lookup hash to begin with. True it is 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 handle this sort of case. All IMHO ;) John -Original Message- From: Briac Pilpré [mailto:[EMAIL PROTECTED]] Sent: 31 January 2002 14:35 To: [EMAIL PROTECTED] Subject: Re: html entity conversion... one liner? 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 = blah; $item =~ tr//(lt;)(gt;)/; 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? Here's a possible suboptimal one-liner approach: #!/usr/bin/perl -w use strict; my $item = gahbuh/gah zoh; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; print $item; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Today is Sweetmorn the 31st day of Chaos in the YOLD 3168 Umlaut Zebra über alles! Missle Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Today is Boomtime the 32nd day of Chaos in the YOLD 3168 Hail Eris! Missle Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html entity conversion... one liner?
$item =~ s//lt;/g; $item =~ s//gt;/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 this: $item = blah; $item =~ tr//(lt;)(gt;)/; 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 unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html entity conversion... one liner?
On Thu, 2002-01-31 at 09:06, KAVANAGH, Michael wrote: I thought it would be good to be able to do this: $item = blah; $item =~ tr//(lt;)(gt;)/; 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 I could be wrong, but I thought tr/// and y/// were only for characters. I think you might want: my %entity = ( '' = 'lt;', '' = 'gt;', '' = 'amp;', ); my $item = blah; $item =~ s/([])/$entity{$1}/ge; -- Today is Sweetmorn the 31st day of Chaos in the YOLD 3168 Missle Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html entity conversion... one liner?
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 = blah; $item =~ tr//(lt;)(gt;)/; 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? Here's a possible suboptimal one-liner approach: #!/usr/bin/perl -w use strict; my $item = gahbuh/gah zoh; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; print $item; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html entity conversion... one liner?
Why *must* it be a one liner. I think my suggestion is easier to understand for someone having to maintain your code. If there is no other reason than I want a one liner to do this on one line, then why not do it on two?? Just because it is possible in one line, doesn't mean it's the best approach. To me this: $item = blah; $item =~ s//lt;/g; $item =~ s//gt;/g; Seems far easier to understand than either this: $item = blah; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; or this: my %entity = ( '' = 'lt;', '' = 'gt;', '' = 'amp;', ); $item = blah; $item =~ s/([])/$entity{$1}/ge; which isn't even a one liner as you have to define a lookup hash to begin with. All IMHO ;) John -Original Message- From: Briac Pilpré [mailto:[EMAIL PROTECTED]] Sent: 31 January 2002 14:35 To: [EMAIL PROTECTED] Subject: Re: html entity conversion... one liner? 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 = blah; $item =~ tr//(lt;)(gt;)/; 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? Here's a possible suboptimal one-liner approach: #!/usr/bin/perl -w use strict; my $item = gahbuh/gah zoh; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; print $item; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html entity conversion... one liner?
Michael Kavanagh wrote: I thought it would be good to be able to do this: $item = blah; $item =~ tr//(lt;)(gt;)/; 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 () to group... any comments on how to make this operation in to a one-liner? $item =~ s{([])} {$1 eq '' ? 'lt;' : 'gt;'}ge; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html entity conversion... one liner?
On Thu, 2002-01-31 at 09:39, John Edwards wrote: Why *must* it be a one liner. I think my suggestion is easier to understand for someone having to maintain your code. If there is no other reason than I want a one liner to do this on one line, then why not do it on two?? Just because it is possible in one line, doesn't mean it's the best approach. To me this: $item = blah; $item =~ s//lt;/g; $item =~ s//gt;/g; Seems far easier to understand than either this: $item = blah; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; or this: my %entity = ( '' = 'lt;', '' = 'gt;', '' = 'amp;', ); $item = blah; $item =~ s/([])/$entity{$1}/ge; which isn't even a one liner as you have to define a lookup hash to begin with. True it is 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 handle this sort of case. All IMHO ;) John -Original Message- From: Briac Pilpré [mailto:[EMAIL PROTECTED]] Sent: 31 January 2002 14:35 To: [EMAIL PROTECTED] Subject: Re: html entity conversion... one liner? 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 = blah; $item =~ tr//(lt;)(gt;)/; 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? Here's a possible suboptimal one-liner approach: #!/usr/bin/perl -w use strict; my $item = gahbuh/gah zoh; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; print $item; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Today is Sweetmorn the 31st day of Chaos in the YOLD 3168 Umlaut Zebra über alles! Missle Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html entity conversion... one liner?
-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 this: $item = blah; $item =~ tr//(lt;)(gt;)/; 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? In addition to all the suggestions you're getting, note that there is the HTML::Entities module on CPAN for encoding and decoding entities. It's part of the LWP distribution, I believe. use HTML::Entities; The one-liner is then: encode_entities($item); HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]