[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] 3 Questions and a Possible -Reply



Peter Van Avermaet writes:

>A previous reply from Jamie McCarthy went in that direction, through a
>sequence of "s" statements. The script that I referred to (in a rather
>vague manner) did something similar with one "tr" statement.

I don't think so;  "tr" replaces single characters with other, single characters.

It might have been something Danny Thomas' script, except replacing the list of numbers with a list of names.  This, for example, would work for any subset of bogus characters:


%bogus_replacement_array = (
      '<' => '&lt;',
      '>' => '&gt;',
      '"' => '&quot;'
      'Ÿ' => '&uuml;'
);

$bogus_character_class = '([\\'
   . join('\\', keys %bogus_replacement_array)
   . '])';

s/&/&amp;/g;
s/$bogus_character_class/$bogus_replacement_array{$1}/eg;


The &amp; substitution has to be done first for obvious reasons;  apart from that, you can add whatever characters you like to %bogus_replacement_array.

(Technically, this isn't about MacPerl, it's about fiddling with the Mac character set in perl;  my apologies to the management...)

--
 Jamie McCarthy          http://www.absence.prismatix.com/jamie/
 jamie@voyager.net        Co-Webmaster of http://www.nizkor.org/