in reply to Removing unwanted chars from filename.
If you are stripping out all characters from a known set then tr is the way to go for 2 reasons. Firstly, it's lightning fast. Secondly you cannot accidentally construct a pattern of more than a single character. Here is a test to demonstrate.
#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 1; my $in = q/xTest-1 [ ] 'copy'.png /; my $want = 'xTest-1copy.png'; my $have = filter ($in); is $have, $want; sub filter { my $str = shift or return ''; return $str =~ tr/A-Za-z0-9.-//cdr; }
🦛
In Section
Seekers of Perl Wisdom