Well, you can simplify the translate to a single line:
use strict; use warnings; my $string = "aabbzzb"; my $oldchars = "//; print `dir *.*`; \\\$string =~ tr/"; eval "\$string =~ tr/$oldchars//d"; print $string; #will print zz
but as you may notice from the sample $oldChars string a savy user could take advantage of the string eval to do interesting stuff.
Probably you would be better to use a regex:
$string =~ s/[$oldchars]//g;
which at least is a little harder to subvert. Better still would be to sanitise $oldchars before it is used in the regex, but how you do that depends a great deal on what is appropriate in oldChars.
In reply to Re: deleting characters from a string but the characters are in a variable
by GrandFather
in thread deleting characters from a string but the characters are in a variable
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |