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

Please advise how I can get "Last modified on ......" on my web page.

I see web pages with:
Last modified on 11/27/2002 5:24:45
This tells me that the web page was last modified on 11/27/02 at 5:24:45 AM.
I have played with some Javascript to do this but it doesnt work in my Netscape 4.77 browser because it gives me the "December 31,1969" date. Anything in CGI I could use?

Replies are listed 'Best First'.
Re: Last mod date of web page
by davorg (Chancellor) on Nov 27, 2002 at 16:09 UTC

    This is off-topic as it has nothing to do with Perl - but I'm feeling generous.

    There are many ways to do it. Here are a couple:

    • Set up your editor so that it automatically inserts a new datestamp in the file each time the file is saved. This is the default behaviour with html-mode in Emacs.
    • If your server supports Server Side Includes then you can include the lines
      <!--#config timefmt="%D" --> This file last modified <!--#echo var="LAST_MODIFIED" -->
      in your file. Of course you then need to ensure that your file is processed by the SSI processor. This is often as simple as giving the file a .shtml extension.
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Last mod date of web page
by Abigail-II (Bishop) on Nov 27, 2002 at 16:24 UTC
    Why are you looking for difficult solutions like CGI or Javascript? When I want a Last modified date, I hit a in vi, followed by Last modified on Nov 27, 2002, followed by an escape. No need for the server to do work on each request, as with CGI or SSI solution (which often break any caching mechanisms), or to have to rely on whether the client has Javascript enabled.

    It even works for plain text files.

    Abigail

      I simply just want to print "Last modification of web was November 27, 2002 at 5:45 AM" where this displays on the web page when the HTML page was last changed.
Re: Last mod date of web page
by tachyon (Chancellor) on Nov 27, 2002 at 17:59 UTC

    For a simple solution that does not hit the server with any real time load you could run a script like:

    my $dir = 'C:/test/'; opendir DIR, $dir or die $!; while (my $file = readdir DIR ) { next unless $file =~ m/\.html?/; my @stat = stat $dir.$file; $mod_time = scalar localtime $stat[9]; # do an inplace edit becaue it is less typing... `perl -pi.bak -e "s!(<MODTIME>[^<]*</MODTIME>)?</BODY>!<MODTIME>$m +od_time</MODTIME></BODY>!i" $dir$file`; } closedir DIR;

    This will read the contents or a dir. Find the .htm .html files. Do a stat on them to get the last modified time. Convert the stat value from epoch time to English. Insert the date in a token that we can modify in the future when we run the script again...

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Last mod date of web page
by rdfield (Priest) on Nov 27, 2002 at 16:07 UTC
    If by "CGI" you mean Perl: stat $0 gives you a lot of information about the current file. You might want to have a look at the documentation (perldoc -f stat).

    rdfield

Re: Last mod date of web page
by BazB (Priest) on Nov 27, 2002 at 23:21 UTC

    An alternative idea - use the built in timestamping functionality of your source control system.
    You are using source control, aren't you? :-)

    Taking CVS, for example, the $Date$ keyword is probably the most applicable - just make sure you stick it in some HTML and you're all set.

    BazB

Re: Last mod date of web page
by strat (Canon) on Nov 28, 2002 at 11:03 UTC
    At my homepage, I use for SSI-pages something like the following:
    <!--#config timefmt="%d.%m.%y %H:%M" --> Last modified: <!--#echo var="LAST_MODIFIED" -->

    This prints something like:
    Last modified: 07.11.02 01:31 Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"