Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Is there any way to successfully use utime in a -pi loop?

by samwyse (Scribe)
on Jul 23, 2012 at 20:17 UTC ( #983231=perlquestion: print w/replies, xml ) Need Help??
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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://983231]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2016-10-21 01:40 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (284 votes). Check out past polls.