in reply to Private Utilities
%cat rename.pl #!/usr/bin/perl =head1 SYNOPSIS rename.pl '<pattern from>/<pattern to>' <filenames> =head1 DESCRIPTION Renames the files listed as <filenames> after performing the substitut +ion using the standard perl regular expression pattern from and to. =head1 EXAMPLES rename.pl 'ready/done' file1-ready file2-ready_to_go renames "file1-ready" to "file1-done" and "file2-ready_to_go" to "file2-done_to_go" =cut use strict; use warnings; my $file; my $old; my $pattern; my $command; unless( @ARGV >= 2) { print "Usage: rename \"patternfrom/to\" <filenames>\n"; exit(1); } # end argument check $pattern = shift(@ARGV); foreach $file (@ARGV) { $old=$file; $pattern .= "/" unless( $pattern =~ m#.*?/.*?/$# ); $command = "\$file =~ s/$pattern"; eval $command; if ( $@ ) { print STDERR "$@"; } # end eval failed check rename($old,$file); } # end rename loop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Private Utilities
by eyepopslikeamosquito (Archbishop) on Nov 30, 2005 at 23:30 UTC | |
by Aristotle (Chancellor) on Dec 01, 2005 at 05:15 UTC |