#!/bin/perl # run the perl program with perl rt.prl # by Jean Roth March 13, 2001 # This program produces the Record Subject Matter Field Content # for the School District Database in html format # It prints out one main rt* web page # and a one detail web page for each Table # The detail web pages show the values & value labels of the Table # Hard code or request which catalog # Catalogs are rt1, rt2a, rt2b, rt3-rt7 $rt = "rt1"; #Hard coding # Interactive: print "Which catalog? rt1, rt2a, rt2b, rt3, rt4, rt5, rt6, or rt7 ?\n"; $rt = ; chomp($rt); while ($rt !~ /rt[1|[3-7]|2a|2b|]/ ) { print "Type the catalog as rt2a, for example\n"; print "Choices: rt1, rt2a, rt2b, rt3, rt4, rt5, rt6, or rt7\n"; $rt = ; chomp($rt); } #end while if ($rt =~ /1/ ) { $fn = "ht" ; $file = "HT (1) -- All households" ; $unit = "School District" ; } elsif ($rt =~ /2a/ ) { $fn = "ps" ; $file = "PS (2a) -- All persons" ; $unit = "School District" ; } elsif ($rt =~ /2b/ ) { $fn = "pt" ; $file = "PT (2b) -- All persons" ; $unit = "School District" ; } elsif ($rt =~ /3/ ) { $fn = "hc" ; $file = "HC (3) -- Households with Children" ; $unit = "School district by enrollment status by age or grade level" ; } elsif ($rt =~ /4/ ) { $fn = "pr" ; $file = "PR (4) -- Parents Living with Children" ; $unit = "School district by enrollment status by age or grade level" ; } elsif ($rt =~ /5/ ) { $fn = "ch" ; $file = "CH (5) -- Relevant Children's Households" ; $unit = "School district by enrollment status by age or grade level" ; } elsif ($rt =~ /6/ ) { $fn = "cp" ; $file = "CP (6) -- Relevant Children's Parents" ; $unit = "School district by enrollment status by age or grade level" ; } elsif ($rt =~ /7/ ) { $fn = "co" ; $file = "CO (7) -- Relevant Children" ; $unit = "School district by enrollment status by age or grade level" ; } print "Your choice was $rt.\nThank you!!!\n"; # Step 0: Print out heading material for the main web page $date = `date`; chomp($date); open (RT, "> /home/web/html/data/sddb/doc/$rt/index.html") or die "Can't write /home/web/html/data/sddb/doc/$rt/index.html"; select(RT); print "\n"; print "\n"; # Step 1: Print out the main web page open (FILE, "/homes/nber/jroth/sddb/$rt.cat"); # Note: Supplemental Tables can have the same name as non-Supplemental Tables $begin = 0; #used to flag when to print the footer of a detail web page $lasttable = 0; #used to flag labels that take more than one line while ($line =) { chomp($line); #remove carriage return # print out the title & heading of the main web page & open its table if ($line =~ /Record Subject Matter Field Content/ ) { ($first, $second) = split (/:/, $line, 2); $title = "SDDB " . $second ; print " $title\n"; print "\n\n"; print "\n
\n"; print "

SDDB

\n"; print "

Record Subject Matter Field Content:

\n"; $second =~ s/\s+//; #remove trailing spaces print "

$second

\n"; print "\n\n"; } #end if ($line =~ /Record # if the Catalog file has supplemental variables, then set a flag so that # an 's' can be later be added to the variable name to distinguish it from # non-supplemental variables & print out a row in the table indicating # that the supplemental variables have begun if ($line =~ /Supplemental Table/i ) { #mark beginning of Supplemental Tables $supp = 1; select (RT); print "\n\n\n"; } #end if ($line =~ /Supplemental # If the line begins with Table, grab the variable name and first line of # the label. Change the variable name to lowercase to be used as a file name # for the detail html files. # Add an "s" to the supplemental variables, if any. # Flag that the last line began with table to concatenate any subsequent # table label lines to the label from the first line if ($line =~ /^Table/ ) { # If the Table is the second or subsequent tables if ($begin == 1 ) { #print out footer of detail html file select (DETAIL); print "\n\n\n
Supplemental Tables
\n"; print "
\n\n\n\n\n"; print "\n\n\n"; $universe =~ s/^\s+//; #remove leading spaces print "\n\n\n"; print "
File: $file
Unit of observation: $unit
Universe: $universe
\n\n\n"; select(RT); } #end if ($begin $begin = 1; $lasttable = 1; ($t, $varname, $label) = split(/\s+/, $line, 3); $filename = $varname; #varname will be used to name the html detail files $filename =~ tr/A-Z/a-z/; #change to lowercase #add an s to the Supplemental Tables to distinguish them from the non-Supplemental Tables if ($supp == 1 ) { $filename = "s" . $filename ; } #print "$filename\n"; $label =~ s/\s+$//; #remove trailing spaces from labels # Step 2: Print out the header for the detail web pages open (DETAIL, "> /home/web/html/data/sddb/doc/$rt/$rt$filename.html") or die "Can't write /home/web/html/data/sddb/doc/$rt/$rt$filename.html"; select(DETAIL); print "\n"; print "\n"; $dlabel = $label; $dlabel =~ s/\[\d{1,4}\]//; #remove bracketed info print "SDDB $t $varname $dlabel\n"; print "\n"; # ($t, $varname, $line) = split(/\s+/, $line, 3); print "\n"; print "\n\n\n"; # print "\n\n\n
                                                                      Field Number
$line\n";  #
\n
\n
";
   $pre = 1;
}  #end if ($line =~ /^Table


#    Step 3:  Get long labels & concatenate (those after ^Table and before /Universe/

elsif ($lasttable == 1 && $line !~ /Universe/ ) {  
   print "$line\n";
   ($first, $label2) = split(/\s+/, $line, 2);
   $label2 =~ s/\s+$//;  #remove trailing spaces
   $label = $label . " " . $label2 ;  #concatenate label2 to label 
   } #end elsif ($lasttable


#    Step 4:  Print the Table name and complete label to the detail & main web page
#  A line with Universe in it indicates that the Table lable is done
elsif ($line =~ /Universe/ ) { 
   ($u, $universe) = split(/:/, $line, 2);
   $universe =~ s/\s+$//;  #remove trailing spaces
   print "
\n
\n\n\n\n\n\n\n"; } #end elsif ($line =~ /Universe/ # Step 5: Concatenate universes for printing to detail file elsif ($lastuni == 1 && $line !~ /Universe/) { $lastuni = 0 ; $universe = $universe . $line; $universe =~ s/\s+$//; #remove trailing spaces } # Step 6: Print Table values & value labels to detail web page else { select (DETAIL); if ($line !~ /calculated|^\s+units?\s+$|^\s+is determined\s+$|^\s+rent\s+$/ ) { #don't print a second Universe line $line =~ s/-18//; $line =~ s/- 9//; $line =~ s/ - //; $line =~ s/\s+$//; #remove any trailing spaces $line =~ s/\s{9}/ /; print "$line\n"; } $lastuni = 0; } #end else } #end while # Step 7: Print out Footing material for the detail & main web page select (DETAIL); print "\n\n\n
\n
\n";
   $lasttable = 0 ;
   $lastuni = 1;
   select (RT);
   print "
$varname$label
\n"; print "
\n\n\n\n\n"; print "\n\n\n"; $universe =~ s/^\s+//; #remove leading spaces print "\n\n\n"; print "
File: $file
Unit of observation: $unit
Universe: $universe
\n\n\n"; select (RT); print "\n\n

\n

\n"; print "\n"; print "
Last Update: March 26, 2001 Created by Jean Roth March 13, 2001
\n"; print "
\n"; print "\n"; `chmod a+r /home/web/html/data/sddb/doc/$rt/*html`; `chgrp web /home/web/html/data/sddb/doc/$rt/*html`;