[SOLVED] Perl: Get file modified date without using stat
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
When I say unsanitised I mean that there may be strange characters or spaces or the file may not exist or may be a relative path that's not correct from your scripts working directory. Basically the data may not be accurate.
You can use system() to call any executable in the system, for example:
You will get that error if $file does not exists.
Try this:
Code:
use IO;
use File::stat;
$file = "/path/to/some/file";
$file_handle = IO::File->new($file,'r') or die "No $file: $!";
$dttm_raw_modified = stat($file_handle)->mtime;
print $dttm_raw_modified;
#!/usr/bin/perl
use File::stat;
$file = '/path/to/some/file';
$st = stat($file) or die "No $file: $!";
$dttm_raw_modified = $st->mtime;
print $dttm_raw_modified;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.