davido is right, it's mostly the variables that have gone missing, and for some reason $_ seems to have been replaced with "sh". Very bad points for a "technical" site. Anyway, I've tried to fix that, and removed a few bugs in the process (like forgetting about $dir in testing if it's a directory). Here it is:
#!/usr/bin/perl -w sub Get_Title { my $file = shift; unless(-f $file) { return("NO INDEX"); } local *HTML; local *_; open(HTML,"<$file"); while(<HTML>){ if(/<title>(.*)<\/title>/i) { return $1; } } return "Untitled"; } my $dir ="/usr/local/apache/htdocs/projects"; my $url ="http://mattwork.potsdam.edu/projects"; opendir(PRJD, $dir); my @dirs = readdir PRJD; closedir(PRJD); print "Content-Type: text/html\n\n"; print "<html><head><title>Project Index Page</title></head><body>\n"; print "<h1>Project Index Page</h1>\n"; print "<ul>\n"; for(@dirs) { if(/^\./) { next; } unless(-d "$dir/$_") { next; } my $file = "$dir/$_/index.html"; my $title = Get_Title($file); print "<li><a href=\"$url/$_/index.html\">$_</a>: $title\n"; } print "</ul></body></html>";

If you don't like the formatting, please don't change the tags. Instead, use CSS to choose different styles for the H1 and LI tags. You'll probably want a smaller H1 font, and you can remove or replace the bullets from the list, for example.


In reply to Re: Dynamic Directory Index help by bart
in thread Dynamic Directory Index help by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.