http://qs321.pair.com?node_id=852217


in reply to Rename files with $EDITOR

The idea behind this script both terrifies, and excites me.

The script itself however frightens me, because there are some edge cases that can have some relaly nasty behavior...

I think the only safe way to deal with all of this is that if you detect your $target is already a key in the hash, you need to mv($target,$tmpfile) and then update the hash, ala: $files{$tmpfile} = $files{$target}; delete $files{$target};. It complicates things because you can't do a simple loop over a one time copy of the keys, but that's not a big deal. Just do a "while (keys %files) { $fname = (keys %files)[0]; ...; delete $files{$fname}; }" type flow instead.