in reply to trying to rename files

Cleaned up code:

#!/usr/bin/perl use strict; use warnings; use File::Spec (); my $dir = '/cdw/home_dir/s006258/MarketingDB'; my $log = 'List_of_files_changed.txt'; opendir(local *DIR, $dir) or die("Cannot open $dir.\n"); open(local *FILES, '>', $log) or die("Cannot open output file $log.\n"); while (defined(my $file = $filereaddir(DIR))) { next unless $file =~ /^append/; my $old = my $new = $file; $new =~ s/^append/aPPend/; $old = File::Spec->catfile($dir, $old); $new = File::Spec->catfile($dir, $new); die("Unable to rename $old: $new already exists.\n") if -e $new; rename($old, $new) or die("Unable to rename $old: $!\n"); print FILES ("$old renamed to $new\n"); }

Updated.

Update: 3rd point was backwards.

Replies are listed 'Best First'.
Re^2: trying to rename files
by Anonymous Monk on Jun 09, 2006 at 20:29 UTC
    I did that and still gives me the same output.... Is the "s/^append/aPPend/;" even relevant? How does it know what file to do a substitution against?