http://qs321.pair.com?node_id=983231

samwyse has asked for the wisdom of the Perl Monks concerning the following question:

The following doesn't generate any errors, but if it's changing the time stamps then something's changing them back immediately. Can anyone help?
#!/usr/bin/perl -pi.bak # Strip DOS CR chars, hopefully without affecting mtime s/\cM//g; if (eof) { @times = (stat($ARGV.$^I))[8,9]; close ARGV; utime @times, $ARGV or warn; }
This is perl, v5.8.8 built for aix-thread-multi, if it matters.

Replies are listed 'Best First'.
Re: Is there any way to successfully use utime in a -pi loop? (ARGVOUT)
by tye (Sage) on Jul 23, 2012 at 21:20 UTC

    You need to close the output file handle there, ARGVOUT. No, I didn't test if that was enough to make it work, though.

    - tye        

      D'oh!!! Thanks, I don't know how I missed that. Well, really, I do. I my scripting confirming that $ARGV was the name of the output file, so obviously ARGV had to be the file itself, right?