in reply to Change utility; code optimization
will slurp all of the file into $filecontents, then you don't need to worry about using join.undef $/; $filecontemts=<DEFILE>
should make the substitution and return the number of times it happened all at once. It will only print if $happens isn't zero. It's a little hard to read, but you get used to it quickly. Then you are only doing one regex on the data, rather than two. (vice versa for case insensitive matching.)print "Changing \"$File::Find::name\" file...\n" if ($happens=($file_c +ontents =~ s/$changefrom/$changeto/g));
I don't know if if($code =~ m/yY/) would be faster than testing for equality, but it is easier to read (at least for me anyway. YMMV)
|
|---|