in reply to Re: regex renaming with existing files
in thread regex renaming with existing files
Hmm, not such a good illustration. You initialise $counter with the string '1', not with the number 1. Perl is smart enough to Do What You Mean, but you are telling people who read your code the wrong thing.
You have also carried over the OP's bad habit of needlessly interpolating variables into strings. Using interpolation for "$filename.[$counter]" is appropriate but elsewhere you should simply use the variable: rename $existingFile, $filename.
If there is no algorithmic reason to use the post increment operators, always use pre increment. Sticking the ++ or -- out the front (++$counter) makes them easier to see which is a Good Thing™.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: regex renaming with existing files
by james28909 (Deacon) on Nov 04, 2014 at 10:24 UTC | |
by GrandFather (Saint) on Nov 04, 2014 at 20:07 UTC | |
by ArifS (Beadle) on Nov 04, 2014 at 14:26 UTC | |
by GrandFather (Saint) on Nov 04, 2014 at 20:12 UTC |