EDIT: tr/// does not support variable interpolation, so I went with s/\Q$_\E//g;
instead
Or, more likely, I'm not doing something right...
I have the following code:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
sub strip_invalid {
my ($str, @chars) = @_;
map { $str =~ tr/$_//; } @chars;
return $str;
}
my @invalid = qw( a e i o u );
print strip_invalid("This is the super sample with vowels.\n", @invalid);
I'd just like to pass a string to strip_invalid()
and have tr///
remove the characters in @invalid
through a map
... Where did I go wrong? (by the way, using regular expressions it works).