#!/usr/local/bin/perl print "Content-type: text/html\n\n"; #### Let the browser know you'll be sending HTML stuff opendir(FORUMDIR, "Msg_Open"); @files = reverse(grep(/.*msg$/,readdir(FORUMDIR))); closedir(FORUMDIR); #### Get a list of files in the directory that holds the messages @files1 = reverse(@files); #### reverse the order so we go from newest to oldest. print qq! Delete Messages

!; #### Start sending the page foreach $file (@files){ $i = 0; open (FILE, "Msg_Open/$file"); foreach () { $element[$i] = $_; $i++; } close(FILE); $post{"$file"} = "$element[0]: $element[4]<\/b><\/a><\/font>($element[3])<\/font><\/input>
"; } #### format each message into a line of HTML and put into an array &rep2rep(""); #### This subroutine recursively sorts the array into a tree structure #### and puts it in the variable $ret print $ret; #### print the variable print ("
<\/center><\/form><\/body><\/html>"); #### print the submit butto and the end of the HTML page sub rep2rep #### subroutine to recursively sort message int a tree structure { $spacer++; #### originally this was a spacer, now it's a counter my @files2 = @files; if ($spacer > 1){@files2 = @files1;} #### spacer is the level, if level is not 1 (otherwise not the root of a thread) #### then use the reversed list my ($file) = @_; #### get the input to the subroutine $file =~ s/\-..........//; #### toss everything after the dash if ($file eq ""){$file = "000000";} #### if it's blank make it all zeroes my ($file2); foreach $file2 (@files2) { if ($file2 =~ /\-$file.msg/) #### compare the message sent as the root to all of the messages, #### if it is part of the thread then add it to the return variable { $ret .= "\n
    "; $ret .= $post{$file2}; $ret .= &rep2rep($file2); #### also recurse it through this subroutine to see if there are replies to it. $ret .= "<\/ul>"; } } $spacer--; #### decriment the level counter $output = ""; #### clean up the subroutine output and end }