Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm trying to get stats on remote files hosted on another domain. Specifically, I would like to retrieve a time stamp for the last modified or last access date. This is so I can rank documents by update or access time. Can this be done in Perl? Please advise o great ones.

Replies are listed 'Best First'.
Re: Remote file stats ...
by cjf (Parson) on Mar 07, 2002 at 03:54 UTC

    You can get the last modified time (and a bunch of other stuff) on a remote file using the head() method of LWP::Simple like so...

    use LWP::Simple; my $url = "http://www.perlmonks.org/yourfile"; my ($content_type, $document_length, $modified_time, $expires, $server +) = head($url);

    Docs for LWP::Simple are here

Re: Remote file stats ...
by beppu (Hermit) on Mar 07, 2002 at 03:56 UTC
    Using the HEAD command that comes with LWP, you can make a HEAD HTTP request which might send back a Last-Modified header. For example (from the shell):

    % HEAD http://ax9.org/index.htm 200 OK Connection: close Date: Thu, 07 Mar 2002 04:03:14 GMT Accept-Ranges: bytes ETag: "9046a85-233-3c64116d" Server: Apache/1.3.22 (Unix) mod_perl/1.26 mod_ssl/2.8.5 OpenSSL/0.9.6 +b Content-Length: 563 Content-Type: text/html Last-Modified: Fri, 08 Feb 2002 17:57:01 GMT Client-Date: Thu, 07 Mar 2002 04:03:14 GMT Client-Response-Num: 1 %