On Thu, Jan 18, 2001 at 12:38:57PM +1030, Paul McCann wrote:
> Hi John,
>
> you asked...
>
> > $_ = "Señor";
> > s~([\x80-\xFF])~$1---~g;
> > print; # Señ---or
> >
> > I want to evaluate ord($1) and then look up in a table that will give
> > me "0x00F1" so that I can print Señ[0x00F1]or.
>
> Maybe something like...
>
> $_ = "Señor";
> %table=(150=>"[0x00F1]",
> 151=>"[0x00F2]"); #whatever the mappings are
> s~([\x80-\xFF])~$table{ord($1)}~ge;
> print;
>
> will get you started. The key is the "e" modifier on the substitute, which
> evaluates the expression in the second slot (in order for the "ord" function
> to, err, function).
>
Although, since scalar hash values interpolate in double-quoted strings
anyway, the /e is actually unnecessary with that replacement.
s~([\x80-\xFF])~$table{ord($1)}~g;
will work just as well.
Ronald