Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by 7stud (Deacon)
on Dec 22, 2012 at 19:06 UTC ( #1010038=note: print w/ replies, xml ) Need Help??


in reply to Re^2: File::Find and replacing spaces in filenames.
in thread File::Find and replacing spaces in filenames.

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 }


Comment on Re^3: File::Find and replacing spaces in filenames.
Select or Download Code
Re^4: File::Find and replacing spaces in filenames.
by Kyshtynbai (Acolyte) on Dec 22, 2012 at 20:03 UTC

    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?

      Because it's unnecessary. Why would you want to perform operations in your code that weren't necessary? Would you write a hello world program like this:

      use strict; use warnings; use 5.012; if ("hello world" =~ /hello/) { print 'hello'; } if ("hello world" =~ /world/) { print " world\n"; } --output:-- hello world

      That program unnecessarily uses program resources, and therefore it is bad programming style.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-07-28 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (209 votes), past polls