Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-12-17 05:12 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (462 votes). Check out past polls.