I got this from a guru pal. Though once you see it, it seems simple; and I don't doubt TIMTOWTDI. It stores the 'stat's of each file in the BEGIN block and restores them in the END block. As a Perl success story: a very slightly tweaked version (with a more elaborate substitution) did a job at work that our Windows NT contractor quoted us $15,000 to do. Viva la Perl.
perl -pi -e 'BEGIN { %s = map { $_ => [stat $_] } @ARGV} s/foo/bar/g; +END { for $f (keys %s) { utime(@{ $s{$f} }[8,9], $f) } }' [files]

Replies are listed 'Best First'.
Re: in-place edit preserving file modification times
by Juerd (Abbot) on Apr 21, 2003 at 15:32 UTC

    As a Perl success story: a very slightly tweaked version (with a more elaborate substitution) did a job at work that our Windows NT contractor quoted us $15,000 to do.

    15k to substitute some stuff?

    /me laughs his ass off.

    Juerd
    - http://juerd.nl/
    - spamcollector_perlmonks@juerd.nl (do not use).
    

      When I asked my boss if I could then have the $15k she laughed hers off too.