I have a directory where a majority of filenames are in the format of basename.ext.new. What I want to do is rename them basename.ext using a perl script. I'm not sure, however, if it's possible to do a substitution on the value of a variable.
If the file ends with .new I want to remove it. I can do it in a shell using the following command:
I've been unable to incorporate the second part where the substitution occurs. Any ideas?
Thanks,
jt
Code:
#!/usr/bin/perl
2 @fnames = qx{ls};
3 $i = 1;
4 $elements = @fnames;
5 print "\@fnames has $elements elements.\n";
6 foreach $element (@fnames) {
7 if ($element =~ /.new$/) {
8 print "$i: $element";
9 $i++;
10 }
11 }
Code:
ls | awk '{print $1}' | perl -pe 's/(.new)//'
Thanks,
jt