#!/usr/local/bin/perl

# This program opens a file containing some header information and uses
#   that text in the HTML document that this perl page generates.

# As in the previous "random.pl" example, it gets a list of all the
#   graphic images in another directory, but it creates an ordered 
#   list of hypertext references to those graphics.
 
$fname = "header.txt";      # Assign file name
open (FPTR, $fname);        # Open file containing HTML header
@headertext = <FPTR>;       # Read the file into an array


srand;                      # initialize random seed
$i=0;
while (<../images/*>) {     # loop through directory and get names of images
  $imagearray[$i++] = $_;   # The "$_" is a default scalar input variable
}

$last = $#imagearray;       # This is a special way to find the highest index 

print "Content-type: text/html\n\n";

print<<EOF;                          # Start printing HTML document

@headertext

<H1> Photo Image Gallery</H1>
<P>
<H3> URL List: </H3>
<OL>
EOF
                                     # Print URLs as List Elements
for ($i=0; $i<=$last; $i++)
   {print "<LI> <A HREF=$imagearray[$i]>  $imagearray[$i] </A> \n";}

                                     # Print rest of document
print<<EOF;
</OL>
<H3>
<A HREF="random.pl">
Back to Random Page
</A>
</H3>
</BODY>
</HTML>
EOF


