I believe merlyn at one time had something very similar to this on his website, although it hasn't been there for some time.
Put directories you want checked in __DATA__, with a trailing '/'. Will generate an HTTP header and a list of files in a div tag with ID "lastmodifiedfiles", for easy CSS application.
Caveat: this will not check subdirectories. For example, if you have a directory "shoes" and you want the program to search shoes/ and shoes/sandals and shoes/sneakers, you must put all three directories in __DATA__. This will probably be changed later.
#!/usr/bin/perl -w use strict; use vars qw( %files $file $dir $fh @files ); print "Content-type: text/html\n\n"; my $count = 1; while(<DATA>){ chomp $_; $dir = $_; $dir =~ s/\A\.\.\/httpdocs//ig; opendir($fh, $_); @files = grep(/\.s?html?$/, readdir($fh)); foreach $file (@files){ my $lm = -M "$_$file"; $files{$lm} = "$dir$file"; } } my @lastfiles = sort {$a <=> $b} keys %files; print q[<div id="lastmodifiedfiles">]; foreach(0..4){ print qq[ <a href="$files{$lastfiles[$_]}">$files{$lastfiles[$_]}</a>, + ]; my $days = $lastfiles[$_]; if($days > 1){ $days =~ /(\d+)\./; print qq[$1 days ago.<br>]; } else{ $days = ($days * 24); if($days > 2){ $days =~ /(\d+)\./; print qq[$1 hours ago.<br>]; } else{ $days = ($days * 60); $days =~ /(\d+)\./; print qq[$1 minutes ago.<br>]; } } } print q[</div>]; __DATA__ ../httpdocs/ ../httpdocs/shoes/ ../httpdocs/shoes/sandals/ ../httpdocs/shoes/sneakers/
Update: changed "@files = grep(/\.htm$|\.html/, readdir($fh));" to "@files = grep(/\.s?html?$/, readdir($fh));"
John J Reiser
newrisedesigns.com
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |