in reply to rename files in directory with new extenstion
I always figured, if you're going to do it, do it right:
#!/usr/bin/perl use strict; my $pattern = shift @ARGV; my ($src, $dest) = ($pattern =~ m/^s(.)([^\1]*)\1([^\1]*)\1$/) or die "1st arg not s/// construct (or construct too complicated)" +; my %to_rename; for my $f (@ARGV) { (! -e $f) && die "$f does not exist; $!"; my $n = $f; $n =~ s/$src/$dest/; ( -e $n or defined $to_rename{$n}) && die "$f would be renamed to $n; clobber detected"; $to_rename{$n} = $f; } while (my ($n, $f) = each %to_rename) { rename $f, $n or warn "Cannot rename $f to $n; $!"; }
OK, I can see bad style there, but it works. I wrote it some time ago...
I called the script ~mv, and it is called as ~mv s/\.old$/.new/ *.old
|
|---|