At 10:05 am -0500 9/4/01, Ken Williams wrote:
>  >So I suppose the answer is yes, though I suspect you'd probably want
>>to substitute rather than translate:
>>
>>$str =~ s/$to_find/$replace_with/;
>>....
>>prints:  hijklkakikukeko
>
>That's not right either, it only replaced instances of the entire string
>"aiueo".  You may mean:
>
>    my $str = "aiueokakikukeko";
>    my $to_find = "aiueo";
>    my $replace_with = "hijkl";
>    my %charmap = map {substr($to_find,$_,1), substr($replace_with,$_,1)}
>                  0..length($to_find)-1;
>    $str =~ s/([$to_find])/$charmap{$1}/g;
>    print $str, "\n";
>    ...
>    prints:  hijklkhkikjkkkl
>
>But it's easier (and perhaps faster) to use eval("tr/$to_find/$replace/").

Sorry; it seems I missed the point entirely. That's not the first 
time, and I doubt it'll be the last. Thanks for correcting me, Ken!
-- 
My brain hurts!
SeanC
                      Mediatek Training Institute
            26 Crart Ave., Berea, Durban, South Africa 
<-- New Address
    phone: +27 (0)31 202 1886              [EMAIL PROTECTED] <-- 
New Phone Number
       fax: +27 (0)31 202 1767 
<-- New Fax Number
                   <http://members.nbci.com/s_carte/>

Reply via email to