Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: File::Find and replacing spaces in filenames.

by Kenosis (Priest)
on Dec 22, 2012 at 17:04 UTC ( #1010032=note: print w/ replies, xml ) Need Help??


in reply to File::Find and replacing spaces in filenames.

  • What happens when "my_file.txt" already exists and you encounter "my file.txt" (same issue with dir names)?
  • Consider just returning if no spaces found (no renaming necessary).
  • Will this renaming break anything that depends on previously-existing paths?


Comment on Re: File::Find and replacing spaces in filenames.
Download Code
Re^2: File::Find and replacing spaces in filenames.
by Kyshtynbai (Acolyte) on Dec 22, 2012 at 17:36 UTC

    1. Well, that is a problem. I'm going to think about it tonight.

    2. like this return 1 if $_ !~ /\s+/; ?

    3. No, it won't; files to process are just photos which are just stored on hdd, no software refers to them.

    Thanks!

      2. like this return 1 if $_ !~ /\s+/; ?

      No, because then you would have to perform a second match, which is unneeded. The s// operator returns the number of substitutions made, and 0 is perl's value for false.

      if ($_ =~ s/ /_/g) { # rename } else { return 1 }

      However, according to the docs for File::Find the return value of the wanted() function is ignored, so just write:

      if ($_ =~ s/ /_/g) { # rename }

        Thank you, now I get!

        Could you please tell why performing second match is bad? It can cause some errors? Or it spends resources of the machine? Or is it just a bad style of programming?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (14)
As of 2015-07-02 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (31 votes), past polls