#!/srvtools/http/bin/perl
# Small utility to split the cyberpals database in two
# One for college and for highschool
# Those that don't match either will be put in both, this way no entries
# are lost.
#
require "../cgiconf.pl";  # Contains the server variables

$rw = "$ENV{'INFOMALL_DOCROOT_RW'}";
$rw = "$rw/studentcenter";

$inputfile = "$rw/cyberpals.db";
$college = "$rw/cyberpals_college.db";
$high = "$rw/cyberpals_high.db";
$none = "$rw/cyberpals_none.db";

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

  print "Opening files.. \n";

open (DAT, $inputfile) || die "Can't find this file: $inputfile\n";
open (COL, ">$college") || die "Can't open output file: $college\n";
open (HIGH, ">$high") || die "Can't open output file: $high\n";
open (NONE, ">$none") || die "Can't open output file: $none\n";

  print "Writing data.. \n";

while ($record = <DAT>) {
   if ($record=~ /^high/i) {
     print HIGH $record;
   }  else {
   if ($record=~ /^college/i) {
     print COL $record;
   } else {
     print NONE $record;
   }
   }
}
