Erik Price wrote:
Erik> I'm just starting learning Perl and I'm trying to write a simple
Erik> Perl script that will change a file's name for me.
Erik>
Erik> All of my filenames match the following pattern:
Erik>
Erik> \w+-\d{2,2}\.php\.noheadscript # ex: "index0-18.php.noheadscript"
Erik>
Erik> and I want to remove the ".noheadscript" part. This can be done
...
Erik> The above script would work fine if I was attempting the
Erik> substitution against a line or some kind of file data, but not
Erik> the filename itself. Can someone give me a pointer?
Right, the contents of a file and the name of the file are different
beasts. You want the Perl "rename" function, which renames a file:
$ perldoc -f rename
And note there's already a (Larry Wall written) Perl script to do what you
want, called, surprisingly, "rename"
$ perldoc rename
That's quite a powerful thing; e.g. from the shell:
$ rename s/.php.noheadscript/.php/ *php.noheadscript
You can use any Perl expression there, not just substitution.
If you don't have or can't find the 'rename' script, here's a version.
rename
Description: Binary data
