Preserve Timestamp

P

pulsar4f

I'm try to search and replace a string in some files, but I don't want
the file's timestamp to change if it doesn't contain the string I'm
searching for. Any ideas?
 
A

Anno Siegel

I'm try to search and replace a string in some files, but I don't want
the file's timestamp to change if it doesn't contain the string I'm
searching for. Any ideas?

None needed, a little systematic search takes you right there.

See "perldoc perlfunc" and check the list headed "Functions for filehandles,
files, or directories". One of the entries has the string "time" in it.
Take it from there.

Anno
 
C

chris-usenet

I'm try to search and replace a string in some files, but I don't want
the file's timestamp to change if it doesn't contain the string I'm
searching for. Any ideas?

Uh, change your algorithm to avoid rewriting the files unless they
contain your matching string.

(The "easy" way of doing this is to continue to write the temporary
file and leave the decision of whether to replace the existing file
with the new modified one or leave the original one intact until the
last moment. At least then you only need to pass through each file once.)

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,446
Latest member
Pycoder

Latest Threads

Top