in reply to Re: How to replace spaces with different chars?
in thread How to replace spaces with different chars?
The line at the bottom is hinting at the fact that this is not practical. What you could do instead of get a list of all the files, then use a regex match to find matching files.
use File::Basename qw( fileparse basename ); my $special_chars_re_class = "[".( join "", map quotemeta, @special_chars )."]"; my ( $dir_qfn, $corrupt_fn ) = fileparse( $corrupt_qfn ); my $glob = quotemeta( $dir_qfn ) . '*'; my $re = $corrupt_fn =~ s{ ( [ ] ) | ( [^\w ] ) }{ defined( $1 ) ? $special_chars_re_class : "\\$2" }xegr; $re = qr/^\Q$dir_qfn\E$re\z/; while ( defined( my $qfn = glob( $glob ) ) ) { next if $qfn !~ $re; say $qfn; }
As written, this assumes the spaces are just in the file name.
This could easily be adapted to check for multiple files at once.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to replace spaces with different chars?
by 5mi11er (Deacon) on Jul 11, 2022 at 14:14 UTC | |
by ikegami (Patriarch) on Jul 11, 2022 at 18:59 UTC |