in reply to Open file without changing modified date/time

Hi

Yes, on a win32 system, the inplace edit has to do it on a temp file, than copy the temp file back to the original. The only solution that comes to mind is to do the implace yourself:

#!perl use strict; use warnings; undef $/; for my $file (@ARGV) { open F, $file or die $!; $_ = <F>; close F; $changed = 0; # put your code here, mark $changed if you made changes # For example: # $changed = s/this/that/g; if ($changed) { open F, ">$file" or die $!; print F; close F; } }
}

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

Replies are listed 'Best First'.
Re^2: Open file without changing modified date/time
by richz (Beadle) on Dec 06, 2004 at 20:52 UTC
    You both have good suggestions but I am going to take up Ted's suggestion. The reason is that I'd rather *really* not change the modified time and change it back if I can avoid it.

    I wanted to make sure there wasn't some easy way I was missing but now it seems there is not.

    Thanks to both of you.

      Why don't you want to change the modified time? It's easily the simplest / easist option.
Re^2: Open file without changing modified date/time
by richz (Beadle) on Dec 08, 2004 at 01:22 UTC
    Ted,

    I followed your approach but wrote my own code to do it. But just in case someone tries to use your code, I think it has a bug. I think the line $_ = <F>; since you will just read one line.

      You forgot to notice this line in Ted's code:
      $/ = undef;
      Look up $/ in perldoc perlvar -- in case you don't know what "slurp mode" is for file reads, that section of the docs will explain it. It's not a bug.
        Oh, very nifty. No, I did not know about slurp mode and that's why I said I *think* there is a bug. I learn new things everyday, thanks guys!