chuckH has asked for the wisdom of the Perl Monks concerning the following question:
What I want is 103_track.mp3 to turn into 403_track.mp3. What I get is a file named 4$1. Thanks in advance.c:> rename.pl .*\.mp3 1(\d\d.*) 4$1
my $inputMask = $ARGV[0]; my $regexSearch = $ARGV[1]; my $regexReplace= $ARGV[2]; my @files = <*.*>; foreach my $file ( @files ) { if ( $file =~ /$inputMask/ ) { my $oldname = $file; $file =~ s/$regexSearch/$regexReplace/; rename($oldname, $file) or die "$oldname to $file failed: $!"; print "renamed $oldname to $file\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: s/// treat rhs as regex
by jwkrahn (Abbot) on Sep 07, 2008 at 06:30 UTC | |
|
Re: s/// treat rhs as regex
by chromatic (Archbishop) on Sep 07, 2008 at 05:12 UTC | |
by AnomalousMonk (Archbishop) on Sep 07, 2008 at 10:14 UTC | |
by chuckH (Initiate) on Sep 11, 2008 at 01:53 UTC |