1. Perl
  2. Operators
  3. File test
  4. here

Get the number of days that have passed since the last update

Use the file test operator "-M" to get the number of days elapsed since the last update .

-M $file

Example program

This is an example that uses the file operator -M to get the number of days that have passed since the last update.

use strict;
use warnings;

# Get the number of days that have passed since the last update.
# -M $file

print "1: Get the number of days that have passed since the last update.\n";
my $file = "a.txt";
if (-e $file) {
  my $from_last_modify = -M $file;
  print "$from_last_modify days have passed since the last update.\n";
}
else {print "$file does not exist.\n"}

Related Informatrion