perlquestion
peppiv
I have a folder of text files named as ../archive. I want to list the files in this directory and print the first 5 lines of each file. <br><br>
As well, I'd like the name of the file to be a link to the original file. Here's what I have so far:
<code>
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
open (HTMLFILE, ">../htdocs/template2.html") || die ("open HTMLFILE failed");
print HTMLFILE "<HTML><HEAD><TITLE>Updated Page</TITLE></HEAD><BODY><CENTER><FONT SIZE='5' FACE='ARIAL'>List of files</FONT></CENTER><BR><font size='2' face='arial'>\n\n";
opendir(HOMEDIR, "../htdocs/archive") || die ("Unable to open directory");
@files = grep !/^\./, readdir(HOMEDIR);
closedir(HOMEDIR);
foreach $file (reverse sort @files) {
print HTMLFILE "<a href=/archive/$file>$file</a><br>\n";
#the upper part of this code reads/prints the list of files and links them
#the next part of this code reads 5 lines of a file
open(STUFF, "../htdocs/archive/$file") || die ("Unable to open file");
while(<STUFF>) {
1 .. 5 ? print HTMLFILE: last;
}
close (STUFF);
}
print HTMLFILE "</font></BODY></HTML>";
close(HTMLFILE);
print "hopefully this works";
</code>
<br>Seperately these pieces of code work, but the integrated version doesn't.<br><br>
Help! Please!<br><br>
<i>peppiv<i>
<br>