Home > Archive > PERL Beginners > October 2007 > How to check the file is modified or not?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to check the file is modified or not?
|
|
| Sivasakthi 2007-10-29, 7:59 am |
| Hi All,
How to check the file is modified or not?
Thanks,
Siva
| |
| Yogesh Sawant 2007-10-29, 8:00 am |
| On Oct 29, 4:09 pm, msivasak...@gmail.com (Sivasakthi) wrote:
> Hi All,
>
> How to check the file is modified or not?
>
> Thanks,
> Siva
1. get the file's modify time using stat function
2. then compare that time with whatever time-date you have
lookout stat in `perldoc perlfunc` or here's the link:
http://perldoc.perl.org/functions/stat.html
cheers
yogesh
| |
| Tom Phoenix 2007-10-29, 7:00 pm |
| On 10/29/07, sivasakthi <msivasakthi@gmail.com> wrote:
> How to check the file is modified or not?
If the file exists at all, it's been modified at least once. But you
seem to want to know something more.
If you want to know whether the file has been modified since a certain
time, you probably want some form of the mtime, the timestamp that you
see when you use the 'ls -l' command, or your system's equivalent. You
can use Perl's stat() function to get the mtime, or you can use the -M
operator to measure the file's modification age in days. Both -M and
stat are documented in the perlfunc manpage.
If you want to know whether the file has the same contents as it once
had, but you don't want to save a copy of the contents for comparison,
you probably want to calculate a digest of the contents, and save
that. (A digest is a short string produced by a cryptographic hash
algorithm.) There are modules on CPAN that can help you to make a
digest for your file; when the digest doesn't match, you know that the
file has been modified.
Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|