[JaxPM] Perl Code - RFC
JONES, WILLIAM C
wcjones at exchange.fccj.org
Fri Dec 8 09:22:31 CST 2000
On the jacksonville-pm-list; Jax.PM'er "JONES, WILLIAM C" <wcjones at exchange.fccj.org> wrote -
Re below code - Current Jax.PM member thoughts would be most appreciated :)
Thx!
-Sneex-
PS - May need to fix e-mail formatting errors -
sorry about that in advance (Outlook via web sux.)
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
$|++;
my $ctr;
my $erc;
my $partA;
my $partB;
my $dir;
my $filename;
my $letter;
my $rawname;
my $lineOne;
my $lineTwo;
######### Phase I Processing... #########
########## Process Cooked file data now...
open (RFILE, "<CD.raw") or die "\n\nCan't open CD.raw for reading: $!\n\n";
open (NFILE, ">CD.Cooked") or die "\n\nCan't open CD.Cooked for writing:
$!\n\n";
while (<RFILE>) {
$ctr++; # Count lines read...
s/\n/ /; # newline to space...
s/^\s+//; # compress leading whitespace...
s/\s+$//; # compress trailing whitespace...
next unless length; # anything to process?
# Groups
if (/^\D{3,4}\s{1}\-/) {
print NFILE "\n\n$_ ";
next;
}
# Course Numbers
if (/^\D{3,4} (\d{4}(\D)?|XXXX)/) {
print NFILE "\n\n$_ ";
next;
}
# Credit Hours
if (/^\d{1} Credit/) {
print NFILE " $_\n ";
next;
}
# Everything else...
print NFILE " $_ ";
} # end while loop
close (RFILE) or die "\n\nCan't close CD.raw: $!\n\n";
close (NFILE) or die "\n\nCan't close CD.Cooked: $!\n\n";
print "\nProcessed $ctr lines...\n\n";
######### Phase II Processing... ########
########## Process Cooked file data now...
$ctr = 0;
open (NFILE, "<CD.Cooked") or die "\n\nCan't open CD.Cooked: $!\n\n";
while (<NFILE>) {
$ctr++; # Count lines read...
chomp;
s/^\s+//; # compress leading whitespace...
s/\s+$//; # compress trailing whitespace...
next unless length; # anything to process?
# Groups
if (/^\D{3,4}\s{1}\-/) {
/^[A-Z]{3,4}/; $dir = $&;
next if (-d $dir);
$erc = system("mkdir $dir") / 256 unless (-d $dir);
die "$! : $erc during create on $dir..." if ($erc);
$letter = substr($dir,0,1);
$erc = system("mkdir $letter") / 256 unless (-d $letter);
die "$! : $erc during create on $letter..." if ($erc);
next;
}
# Course Numbers
if (/^\D{3,4} (\d{4}(\D)?|XXXX)/) {
$lineOne = $_;
/^[A-Z]{3,4}/; $partA = $&;
/(\d{4}(\D)?|XXXX)/; $partB = $&;
$filename = $partA . $partB . ".html";
$rawname = $partA . $partB;
$filename =~ s/\s//;
$rawname =~ s/\s//;
print "Working on both $rawname \& $filename\n";
if (-e "$dir/$filename") {
print "WARNING: $dir/$filename duplicate; renaming to $dir/X$filename
... \n";
$filename = 'X' . $filename;
}
if (-e "$dir/$rawname") {
print "WARNING: $dir/$rawname duplicate; renaming to $dir/X$rawname
... \n";
$rawname = 'X' . $rawname;
}
open (OFILE, ">$dir/$filename") or die "$! while trying
$dir/$filename";
open (IFILE, ">$dir/$rawname") or die "$! while trying
$dir/$rawname";
$erc = system("cd $letter && ln -s ../$dir/$filename .") / 256 unless
(-e "$letter/$filename");
die "FATAL: $! : $erc during link on $letter/$filename..." if ($erc);
$erc = system("cd $letter && ln -s ../$dir/$rawname .") / 256 unless
(-e "$letter/$rawname");
die "FATAL: $! : $erc during link on $letter/$rawname..." if ($erc);
print OFILE "<HTML><HEAD><TITLE>FCCJ Course Description:
$rawname</TITLE>
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;
charset=iso-8859-1\"></HEAD>
<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"
LINK=\"#006699\" VLINK=\"#009933\" ALINK=\"#999999\">
<SCRIPT LANGUAGE=\"JavaScript\"> <!-- Begin
if (window != top) top.location.href = location.href; //
End -->
</SCRIPT><IMG SRC=\"http://www.fccj.org/logo.gif\"
WIDTH=\"101\" HEIGHT=\"144\">
<FONT SIZE=\"4\" COLOR=\"#000000\"
FACE=\"sans-serif\">College Credit Course Description: $rawname</FONT>
<HR NOSHADE SIZE=\"1\" WIDTH=\"100%\">
<P STYLE=\"face:monospace, fixed, sans-serif; size:14pt;
bgcolor: white; color: \"#006699\"; !important\">
<BR><UL><FONT SIZE=+1 FACE=monospace
COLOR=\"#006699\">$lineOne</FONT>";
print IFILE "$lineOne\n";
next;
} else {
$lineTwo = $_;
print OFILE "<LI><FONT SIZE=+0 FACE=sans-serif
COLOR=BLACK>$lineTwo</FONT></UL>\n</BODY></HTML>";
print IFILE "$lineTwo\n";
next;
}
} # end while loop
close (NFILE) or die "\n\nFATAL: Can't close source file: $!\n\n";
close (IFILE) or die "\n\nFATAL: Can't close html file: $!\n\n";
close (OFILE) or die "\n\nFATAL: Can't close text file: $!\n\n";
print "\nProcessed $ctr lines...\n\nCreating symbolic file and directory
links, please wait...\n\n";
######### Phase III Processing... #######
########## Process Cooked file data now...
###########################################################
# Make ln -s Directory links from Uppercase to Lowercase...
# -Sneex- :]
$ctr = 0;
my $pwd = `pwd`;
opendir TARGETDIR, "." or die "FATAL: Can't open $pwd : $! ";
my @dir = grep !/^\./, readdir TARGETDIR;
closedir TARGETDIR;
foreach (@dir) {
s/\s//; # Should not be any spaces in these dir names...
next if (/\.(\.)?/); # Is it a file with dots in it?
# next if (-f $_); # or is it a plain old file?
print "Working on $_ \n" unless (-f $_);
my $lc = lc($_); $ctr++;
$erc = system("ln -s $_ $lc") / 256;
die "FATAL: $erc $! $? error occurred...\n" if $erc;
}
print "\nProcessed $ctr directory links...\n\nDone!\n\n";
__END__
Any project notes go here...
Jax.PM Moderator's Note:
This message was posted to the Jacksonville Perl Monger's Group listserv.
The group manager can be reached at -- owner-jacksonville-pm-list at pm.org
to whom send all praises, complaints, or comments...
More information about the Jacksonville-pm
mailing list