@a = ; $na = @a; print " na $na\n"; @srch = ("MTH ","Section ","credits","Registration #","Time: ","Dates: ","Location: ","Capacity: ","Instructor: "); # most of the data is the 2nd table data item on the line; # some data immediately follows the srch string. @srchtype = (1, 1, -1, 2, 2, 2, 2, 1, 2); $nsrch = @srch; sub td2{ $tablerow = $_[0]; $itd = index($tablerow,"")+4; $jtd = index($tablerow,"")-1; $tabledata1 = substr($tablerow,$itd,$jtd+1-$itd); $tablerow = substr($tablerow,$jtd+5); $itd = index($tablerow,"")+4; $jtd = index($tablerow,"")-1; $tabledata2 = substr($tablerow,$itd,$jtd+1-$itd); } @srchflags = (); @srchdata = (); for ($isrch=0; $isrch<$nsrch; $isrch++){ @srchflags = (@srchflags,0); @srchdata = (@srchdata,""); } open(COURSESCHEDULE,">course_schedule.txt"); for ($ia=0; $ia<$na; $ia++){ open(INFILE,"<".@a[$ia]); @b = ; close(INFILE); for ($isrch=0; $isrch<$nsrch; $isrch++){ @srchflags[$isrch] = -1; # scrchflags[$isrch] will be the line number where the data for @srch[$isrch] is found @srchdata[$isrch] = "";} $nb = @b; print " nb $nb\n"; for ($ib=0; $ib<$nb; $ib++){ $line = @b[$ib]; for ($isrch=0; $isrch<$nsrch; $isrch++){ if(@srchflags[$isrch] == -1){ $ifound = index($line,@srch[$isrch]); if($ifound > -1){ print $line; print &td2($line)."\n"; @srchflags[$isrch] = $ib; if(@srchtype[$isrch]==-1){ @srchdata[$isrch] = substr($line,$ifound-6);} if(@srchtype[$isrch]==0){ @srchdata[$isrch] = substr($line,$ifound); } if(@srchtype[$isrch]==1){ @srchdata[$isrch] = substr($line,$ifound+length(@srch[$isrch])); } if(@srchtype[$isrch]==2){@srchdata[$isrch] = &td2($line);} $ifont = index(@srchdata[$isrch],"<\/font>"); print " ifont $ifont\n"; if($ifont>-1){ @srchdata[$isrch] = substr(@srchdata[$isrch],0,$ifont);} print " srchdata @srchdata[$isrch]\n"; } } } }; for($isrch=0; $isrch<$nsrch; $isrch++){ # if(@srch[$isrch] eq "MTH "){ # $iMTH = index(@srchdata[$isrch],"MTH "); # @srchdata[$isrch] = substr(@srchdata[$isrch],$iMTH+4,3);} if(@srch[$isrch] eq "Section "){ # $iSEC = index(@srchdata[$isrch],"Section "); # @srchdata[$isrch] = substr(@srchdata[$isrch],$iSEC+8,3); # Lines "Section is Open" or "Section is Closed" might appear # and be mistaken for the section identifier. # Since a section identifier must always appear before a credits line, # If the phrase "Section" is found in a line after the "credits" line, # set the section data to " ". if(@srchflags[$isrch]>@srchflags[$isrch+1]){@srchdata[$isrch]=" ";} } if(@srch[$isrch] eq "credits"){ $iCRE = index(@srchdata[$isrch],"credits"); if($iCRE>-1){@srchdata[$isrch] = substr(@srchdata[$isrch],$iCRE-6,5);} } if(@srch[$isrch] eq "Capacity: "){ $iSE = index(@srchdata[$isrch]," se"); if($iSE>-1){@srchdata[$isrch]=substr(@srchdata[$isrch],0,$iSE);}} print @srch[$isrch].@srchdata[$isrch]."\n"; print COURSESCHEDULE @srch[$isrch].@srchdata[$isrch]."\n"; } print "\n"; print COURSESCHEDULE "\n"; } close(COURSESCHEDULE);