http://www.perlmonks.org?node_id=11147275

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I am trying to get rid of unwanted chars from a filename, cant get the sub "filter" to work, any better way for doing this?
#!/usr/bin/perl use strict; use warnings; # Check filename my $file_name = "xTest-1 [ ] 'copy'.png "; my $input = filter( $file_name) || ''; print "\n*$input* \n"; ### Looking to get this: xTest-1copy.png sub filter { my $str = shift || ''; $str =~ s/[^[:ascii:]]//g; # strip everything but ASCII characters #$str =~ s/[^!-~\s]//g; return $str; }
Thanks for looking!