in reply to substitute using a hash

Although there's undoubtedly a perl module out there doing what you want to do from the looks of it (and it's likely to be HTML::Entities), here's some code to help you on your way
my %iso8859 = ( "\xA0" => ' ', "\xA1" => '¡', "\xA2" => '¢', "\xA3" => '£', "\xA4" => '¤', "\xA5" => '¥', "\xA6" => '¦', ); my $string = "a £ a penny"; my $regex = join '|', map quotemeta, keys %iso8859; $string =~ s/($regex)/$iso8859{$1}/g; print $string; __output__ a £ a penny
You may not need the quotemeta() in the map() but I've just added it 'just in case'.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: substitute using a hash
by vinfizz (Initiate) on May 07, 2002 at 17:38 UTC
    Yup. That did the trick. Very cool. I'll also look at HTML::Entities. If it doesn't have this in there, I'll be sure to contribute this snippet. Thanks!