I am using the File::Copy module to copy a file in Perl:
#! /usr/bin/perl -w
use File::Copy;
copy("somefile.log", "copiedfile.log");
I would like to preserve timestamps (particularly the modification time), but this doesn't appear to be an option.
Is there a straightforward way to achieve this without resorting to making a system call to "cp -p"?
You can use stat to get the timestamp and utime to set it. If you can get away with it, system
isn't always bad. You're never going to make something faster than cp -p
. You'd think that File::Copy would do it, but on unix it doesn't. Abigail filed a RT #96158, but it was closed with no action. He has a presentation about its brokenness, but I haven't seen it online.
Check File::Copy. Look under syscopy
or rmscopy
. It talks about timestamps there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With