You print the contents of @mtime
, but you placed the result in $mtime
. Always use use strict; use warnings;
. It would have found your problem.
Your code should look like one of the following:
Without File::stat (
stat
returns a list):use strict; use warnings; my $file = "samplefile"; my $mtime = (stat($file))[9]; die "Can't stat file: $!\n" if !defined($mtime); printf("%d\n", $mtime);
(EXPR)[9]
returns the 10th element of the listEXPR
returns, or undef if the list isn't that long. This is a scalar you assigned to$mtime
, not@mtime
.With File::stat (
stat
returns an object):use strict; use warnings; use File::stat; my $file = "samplefile"; my $stat = stat($file); die "Can't stat file: $!\n" if !$stat; printf("%d\n", $stat->mtime);