From 0b369171e36a45cf55bccc1727de62d5a6f1e119 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 20 Aug 2005 05:57:25 +0000 Subject: [PATCH] Error checking on file opens --- perl/schedproc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/perl/schedproc b/perl/schedproc index f06a778..dab1f18 100755 --- a/perl/schedproc +++ b/perl/schedproc @@ -48,7 +48,7 @@ die "Invalid arguments\n" unless GetOptions(\%opts, 'schedule=s', 'grades=s', 'name=s', 'format|f=s', 'config|F=s', 'out|o=s'); if (-r $opts{'config'}) { - open CONFIG, $opts{'config'}; + open CONFIG, $opts{'config'} or die $!; while() { s/\#.*//; next unless m/^([^=]*)=(.*)/; @@ -180,7 +180,7 @@ sub get_grades { sub get_faculty_email { my ($name, $school, $email); if((-f $ENV{'HOME'} . "/public_html/faculty.csv") && ! %faculty) { - open INS, $ENV{'HOME'} . "/public_html/faculty.csv"; + open INS, $ENV{'HOME'} . "/public_html/faculty.csv" or die $!; while($_ = ) { chomp; m/"([^"]*)",([^,]*),([^,]*)/; # " @@ -268,7 +268,7 @@ sub do_mhc_schedule { my @lines; foreach my $name (<$file/[1-9]*>) { next unless $name =~ /^$file\/[1-9][0-9]*$/; - open FH, $name; + open (FH, $name) || die $!; @lines = ; close FH; foreach (@lines) { @@ -278,12 +278,12 @@ sub do_mhc_schedule { my $i=0; foreach (@mhc) { while(-f ++$i) {} - open FH, ">$file/$i" or die $!; + open (FH, ">$file/$i") || die $!; print FH $_; close FH; } } else { - open(STDOUT, ">" . $file) if(defined($file)); + open(STDOUT, ">" . $file) || die $! if(defined($file)); print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n"; print join("\n", @mhc); } @@ -295,7 +295,7 @@ sub do_csv_schedule { my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.); my ($current, @mhc, @schedule); @schedule = get_schedule(@_); - open(STDOUT, ">" . $opts{'out'}) if(defined($opts{'out'})); + open(STDOUT, ">" . $opts{'out'}) || die $! if(defined($opts{'out'})); foreach my $row (@schedule) { map {s/\n/-/g if defined; $_} %$row; my $id=generate_id($row->{'id'}); @@ -320,8 +320,8 @@ sub do_vcalendar_schedule { my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU"); my $file = $opts{'out'}; my @schedule = get_schedule(@_); - open(STDOUT, ">>" . $file) if(defined($file) && (! -d $file)); - open(STDOUT, ">/dev/null") if(defined($file) && (-d $file)); + open(STDOUT, ">>" . $file) || die $! if(defined($file) && (! -d $file)); + open(STDOUT, ">/dev/null") || die $! if(defined($file) && (-d $file)); print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n"; foreach my $row (@schedule) { map { s/\n/-/g; $_} %$row; @@ -369,7 +369,7 @@ sub do_xml_schedule { my $schedule = { class => [ get_schedule(@_) ] }; my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule'); if($file) { - open FH, ">$file"; + open FH, ">$file" || die $!; print FH $xml; close FH; } else { @@ -382,7 +382,7 @@ sub do_html_schedule { my $shade = "dark"; my @schedule = get_schedule(@_); if($opts{'out'}) { - open FH, ">" . $opts{'out'}; + open (FH, ">".$opts{'out'}) || die $!; select FH; } print ''."\n
"; @@ -427,7 +427,7 @@ sub do_html_grades { my ($row); my $shade = "dark"; if($opts{'out'}) { - open FH, ">" . $opts{'out'}; + open (FH, ">".$opts{'out'}) || die $!; select FH; } print ''."\n"; @@ -475,4 +475,3 @@ if ($opts{'format'} eq "xml") { } else { die "Unknown format. Try specifying --format.\n" } - -- 2.30.2