[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [FWP] How to do variable interpolation in a tr substitution string
> > Why am I not able to do this as is in s/([a-z])/$h{$1}/g; etc?
>
> Oh, you're no fun anymore!
>
> > {tr/a-z/$compstr/;print $_;
>
> RTFM perlop(1):
>
> Note that because the transliteration table is
> built at compile time, neither the SEARCHLIST nor
> the REPLACEMENTLIST are subjected to double quote
> interpolation. That means that if you want to use
> variables, you must use an eval():
>
> eval "tr/$oldlist/$newlist/";
> die $@ if $@;
>
> eval "tr/$oldlist/$newlist/, 1" or die $@;
>
unless you have fun finding an answer...
instead of "tr" use "s":
s/\w/newchar($1)/seg;
would allow you to write your own tr, no? a bit slower than
blind tr, but think of the possibilities:
s/\w+/sayit( $1 )/seg;
sub sayit
{
my $word = shift;
if( $dictonary{$word} )
{
print AUDIO $dictonary{$word};
}
else
{
print AUDIO map { $dictonary{$_} } split //, $word;
}
}
might make a q&d response filter for your automated computer
butler.
aside: another good resource for questions like this are
mailing lists of the local Perl Mongers. these normally
have fewer posts than lang.perl.misc and don't require a
newsfeed. see the existing groups at pm.org for the one
near you.
--
Steven Lembark 2930 W. Palmer St.
Chicago, IL 60647
lembark@wrkhors.com 800-762-1582
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe