I want to count the number of occurrences of various characters in a string. I can do that with
$ans=($str=~tr/z//);
to count the z's in the string. But I want to change that based on a loop or a command line parameter (e.g., setting $SrchStr=ARGV[0], and doing somethuing like
$ans=($str=~tr/$SrchStr//);
This doesn't work because of compile-time issues, and supposedly there is a way to do this using eval (), but I don't know how.
Does anyone? Or is there another way to accomplish this simple task?