Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: How to replace spaces with different chars?

by ikegami (Patriarch)
on Jul 06, 2022 at 21:00 UTC ( [id://11145312]=note: print w/replies, xml ) Need Help??


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
    I'm going to parrot Ikegami " this is not practical ".

    The real answer is to fix or replace the tool that gave you the incorrect output in the first place.

    -Scott

      Well, I was referring to doing 625 stat calls to check if a file exist. List a directory isn't impractical. Obviously, it would be better if the source could be fixed, but the solution in the post to which you replied is works fine.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145312]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found