Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
$dir="c:/corrupt"; use File::Find; find(\&dofile, $dir); sub dofile{ if($File::Find::name =~ /.txt/){ open(FILE, "$File::Find::name") or die "$!"; @lines=<FILE>; close(FILE); #remove the offending space on 1st line if(substr($lines[0], 3, 1) eq " "){ #get mtime $ENV{TZ}="GMT"; $savetime=(stat("$File::Find::name"))[9]; print "corrupt line 1, repairing $File::Find::nam +e..."; $lines[0]=substr($lines[0], 0, 3, "") . substr($l +ines[0], 1); unlink("$File::Find::name") or die "$!"; open (FILE, ">>$File::Find::name") or die "$!"; print FILE @lines; #write back old mtime utime($savetime, $savetime, "$File::Find::name") +or die "$!"; close(FILE); print "done\n"; } }}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: alter file without changing mtime?
by merlyn (Sage) on Aug 14, 2003 at 13:43 UTC | |
by Anonymous Monk on Aug 14, 2003 at 14:05 UTC |