#!/usr/bin/perl -w use strict; use Getopt::Long; ((my $progname = $0) =~ s/^.*(\/|\\)//ig); # basename $0 # Parse options my $no_verbose_progress = 0; my $usage = 0; GetOptions('quiet' => \$no_verbose_progress, # be quiet 'help|?' => \$usage # help! ); # Print usage if ($usage) { usage(); } unless ($ARGV[0]) { print "Specify a CSV file name as the program's argument (e.g. glossary.csv)\n"; usage(); } open (CSV, "< $ARGV[0]"); # Start writing table file, and write table header open TABLE, "> atoz.html" or die $!; print TABLE << "END"; 1623:204 Passage Names Glossary

Steinbrückenhöhle Passage Names Glossary

A -- B -- C -- D -- E -- F -- G -- H -- I -- J -- K -- L -- M -- N -- O -- P -- Q -- R -- S -- T -- U -- V -- W -- X -- Y -- Z

END ; # starting to read in csv file, eat header line my ($name, $file, $fragment, $desc, $ety); my $output=""; my $templine; my $lcletter; my $letter = ""; unless ($no_verbose_progress) { print "Progress: *"; } my %areanames = ("ariston.html", "Deep South", "entrance.html", "Near End", "midlevel.html", "Midlevel", "millennium.html", "Millennium", "nopain.html", "NPNG / Pleasuredome", "rhino.html", "Rhino", "swings.html", "Swings", "treeumphant.html", "Tree", "uworld.html", "Gaffered / Underworld", "subsoil.html", "Subsoil"); # While loop which reads in each line of csv file while () { chomp; # Split single line into all the fields ($name, $file, $fragment, $desc) = &parse_csv($_); # Last field of CSV file can have weird form-feeds etc. Kill them $desc =~ s/\r//; if(uc(substr($name, 0, 1)) ne $letter) { $letter = uc(substr($name, 0, 1)); $lcletter = lc($letter); $output = "$output

$letter

\n"; } # Construct XHTML line if($fragment) { $templine = "
$name
" } else { $templine = "
$name
" }; $templine = "$templine\n
[$areanames{$file}] $desc"; # if ($ety) # { # $templine = "$templine\n($ety)"; # } $templine = "$templine
\n"; $output = "$output$templine"; unless ($no_verbose_progress) { print "*"; } } print TABLE << "END";
$output

END close TABLE; unless ($no_verbose_progress) { print "\nInformation: Done\n"; } # Parse the CSV file sub parse_csv { my $line = $_[0]; my @parsedline = (); my $field = ''; while ($line =~ m{ \G(?:^|,) (?: "((?> [^"]*) (?> "" [^"]*)*)" | ([^",]*)) }gx) { if ($2) { $field = $2; } elsif ($1) { $field = $1; $field =~ s/""/"/g; } else { $field = ''; } push(@parsedline, $field); } return(@parsedline); } # Usage sub usage { print << "EOF"; USAGE: $progname [-options] -q, --quiet Be quiet about progress -h, --help Show this message EOF exit(0); }