Scrat has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone
I'm new to Perl and find the learning process both exciting and challenging. I'd like some feedback on the following please:
#!/usr/bin/perl use strict; use warnings; my $dir = "C:\\Tickets"; if (chdir "$dir") { opendir (DIR, $dir); my @fileList = readdir DIR; foreach my $oldname (@fileList) { next if -d $oldname; my $newname = $oldname; $newname =~ s/Closed/Open/; rename $oldname, $newname; } } else { print "Error - Please check that $dir exists and is accessible.\n" +; } closedir (DIR);
It renames all files in $dir containing the word "Closed" in the filename to "Open". Is there a shorter / better way of accomplishing this task? Any advice or suggestions are welcome.
|
|---|