[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Another example of using perl to create HTML



Another great use of Perl is to convert databases and spreadsheets
into HTML for publication on the web. I used the following program
to take a list of the works of Igor Stravinsky sorted by year
and produce an HTML document. I'd entered the information inot
a spreadsheet, and saved the file as Text only which separates
the fields by tab marks. My record collection is in Hypercard,
and I'd used Hypertalk to create individual files for each CD/Record
with a file name based on the short id of the Hypercard card.
I stored these numbers on the work list with spaces as separators.
Anther field is used to store the name of another file
in a subdirectory for commentarys.

The final result is at http://www.ozemail.com.au/~caveman/Stravinsky

Under this directory are subdirectories "Records" for my
recordings and "Notes" for commentary files.

I hope this program is useful for ideas and generating
feedback

Thanks for listening,
Charles


#!/bin/perl
#
# MacPerl program written by Charles Cave to convert a tab delimited
# text file into HTML.  Date written 26th December 1995

require "GUSI.ph" ;

# choose the tab delimited file saved from Excel
$infile = &MacPerl'Choose(
     &GUSI'AF_FILE, 0, "", "");

open(IN,$infile) || die "could not open input file";
open(OUT,">".$infile.".htm") || die "could not open output file";

$lastcode = 7777;
#
# my implementation of a table of descriptions for classication codes
#
$catdesc{1} = "Ballet";
$catdesc{2} =  "Opera";
$catdesc{3} =  "Dramatic";
$catdesc{4} = "Oratorio";
$catdesc{5} = "Orchestral/Symphonic";
$catdesc{6} = "Choral";
$catdesc{7} = "Solo Vocal";
$catdesc{8} = "Chamber and Instrumental";
$catdesc{9} = "Piano";

$catdesc{99} = "Stravinsky Chronology";
print OUT "<HTML><HEAD><TITLE>Stravinsky Works By Name</TITLE>\n";
print OUT "</HEAD><BODY BGCOLOR=\"#FFFFFF\"><HR>\n\n";
$lastyear = 0;

while (<IN>) {
  chop;
  s/"//g;
# work out the hex codings by saving sample text in BBEDIT
# and use hex dump to display the codings
  s/\x8F/&egrave;/g;
  s/\x8E/&eacute;/g;
  s/\x88/&agrave;/g;

# break out the tab delimited line inot variables
# mcat is he music category code (see above)

  ($mcat, $title, $recom, $ondisc, $opus, $year, $notes, $document) =
         split(/\t/, $_);
  if ($lastyear != $year) {
# change in year (breakpoint), so output a heading
      $lastyear = $year;
      print OUT "\n<HR>\n<H2>$year</H2>\n\n";
   }
  print OUT "<b>";
# include a reference to another document of notes
  if ($document ne "") {
     print OUT "<A HREF=\"./notes/$document.htm\">$title</A>";
  } else {
     print OUT "$title";
  }
  print OUT "</b> ($catdesc{$mcat})\n";

# this field is a flag to indicate a recommended work
  if ($recom ne "") {
      print OUT " <IMG SRC=recom.gif ALT=\" [Recommended] \"> ";
  }

  if ($ondisc ne "") {
# convert the list of keys into a list of HREFS
     @discs = split(' ', $ondisc);
     foreach (@discs) {
       print OUT "<A HREF=\"./rec/R$_.htm\">R</A> ";
     }
     print OUT "\n";
  }
  if ($notes ne "")  {
     print OUT "<BR><FONT SIZE=2>$notes</FONT>\n";
  }
  print OUT "<P>\n\n";


} ;
print OUT "\n\n<HR>\n</BODY></HTML>\n\n";

close(OUT) ;