#!/usr/bin/perl
# Random Access
# create.pl version 2
#   input: a list of images and a template
#   output: a form with a listbox of images

use strict;

# Input is a file of image urls and associated text,
# separated by a tab.
my $buf;
my $options;
while ($buf = <>) {
  chop ($buf);
  my ($thisImgsrc, $thisText) = split (/\t/, $buf);

  # Truncate if necessary.
  $thisText =~ s/^(.{40,60})\s.*$/\1 . . ./s;

  $options .= "<option value=\'$thisImgsrc\'>$thisText</option>\n";
}

# Grab the template.
my $template;
undef $/;
die "Couldn't open template.htm\n"
  if !open (INFILE,"template.htm");
$template = <INFILE>;
close (INFILE);

# Replace <%options%> tag in template.
$template =~ s/<%(.*?)%>/eval($1)/gse;

print $template;