in reply to Dynamic file renaming and globbing

I would use readdir to read the names of the files that need to be renamed.
Then I'd only glob for those files that would potentially collide.
my $existingfiles_dir; my $newfiles_dir; my $dest_dir; opendir XFD, $existingfiles_dir or die "read $existingfiles_dir : $! +"; opendir NFD, $newfiles_dir or die "read $newfiles_dir : $!"; for my $file ( readdir NFD ) { # parse my( $num, $ver, $ext ) = $file =~ /(\d+x)(\d*)(\..*)/; # find the last of the files it might collide with: my( $last ) = sort { $b <=> $a } # sort version numbers descending map { /^$num(.*)\Q$ext/ ? $1 : () } readdir XFD; rewinddir XFD; # take the next available number: $ver = $last ? $last + 1 : ''; rename $file, $num.$ver.$last; }

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.