in reply to Rename *_valid1.csv to .csv

But you did not use the code as you posted. What is @list?

use strict; use warnings; foreach my $vcsv (glob "D:/CPPDaily/SOURCE/SOURCE/HMS/*_valid1.csv") { (my $csv = $vcsv) =~ s/_valid1(\.csv)$/$1/i; if (-e $csv) { warn "$vcsv cannot be renamed: $csv already exists\n"; next; } rename $vcsv, $csv or die "failed to rename $vcsv -> $csv\n"; }

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Rename *_valid1.csv to .csv
by Ma (Novice) on Nov 05, 2013 at 14:46 UTC
    Thank you. Yes, I took the relevant portion from the main program so that its easy to explain. The code you posted worked perfectly, except that it does not overwrite the file if it already exist. Any way to overwrite the file?
      Check the documentation, but I doubt it. You can precede the renamewith an unlinkto work around the limitation, if it exists.