trying to use a variable as a pattern in a tr operator statement. The camel book p.76 says to use eval like so:
eval "tr/$oldlist/$newlist/";
Using perl_5.26.1 on Linux there are two things wrong with that: a) using quotes as above eval gives an error message. So you must put it in a block using braces. b) even in braces it does not work. What am I doing wrong? here is the code and ouput:
$kards = -99;
$bad="AKQJT98765432KKKK";
$card='K';
eval {print "eval is testing for $card in $bad \n";
$kards = $bad =~ tr/$card//; # tried also tr/$card/$card/; same result.
};
print "Num of $card in $bad = $kards \n";
$king = $bad =~ tr/K//;
print "Num of K in $bad is = $king \n";
=cut
Returns the following:
eval is testing for K in AKQJT98765432KKKK
Num of K in AKQJT98765432KKKK = 0
Num of K in AKQJT98765432KKKK is = 5
=end