Web Automation: Dynamic Directory Indexing Page 4
More robust HTML for prettiness
I'd also like to shamelessly plug Lincoln Stein's CGI.pm
module, which is available on CPAN, and probably is already in your Perl
distribution. I use this module to take a lot of the HTMLizing out of my hands.
I wrote this example using no modules, so you could see what was going on, but
I highly recommend using CGI.pm to do a lot of the HTML stuff for you.
Full Text of this Example
1 : #!/usr/bin/perl -w
2 :
3 : sub Get_Title {
4 : my =shift;
5 : unless(-f "") { return("NO
INDEX"); }
6 : open(HTML,"<");
7 : while(<HTML>){
8 : if(sh=~ /<title>(.*)<\/title>/i) {
9 : close HTML;
10: return "";
11: }
12: }
13: close HTML;
14: return "Untitled";
15: }
16:
17: my ="/usr/local/apache/htdocs/projects/";
18: my ="http://mattwork.potsdam.edu/projects/";
19: opendir(PRJD,"");
20: my @dirs=readdir PRJD;
21: closedir(PRJD);
22: print "Content-Type: text/html\n\n";
23: print "<html><head><title>Project Index
Page</title></head><body>\n";
24: for(@dirs) {
25: if(sh=~ /^\./) { next; }
26: unless(-d sh) { next; }
27: my ="sh/index.html";
28: my =Get_Title("");
29: =~ s///i;
30: print "<a href=\ "\ "></a>\n";
31: }
Matthew Keller specializes in server technologies, with bias towards Linux, Solaris and the Apache Web server. Besides working for SUNY Potsdam, he provides numerous consulting services, has co-authored a couple books about Apache, and even manages to wrestle a mountain every now and then. Visit his personal Web site.
