#!/usr/bin/perl -w use strict; use CGI qw(:standard); my ($block_ref, $event_ref) = get_block(); print header(), start_html("Block Order Script"), h1("The Next Block Order is: "); my ($hour, $min, $day, $dotw) = (localtime)[2, 1, 7, 6]; my $time = sprintf "%02d%02d", $hour, $min; # Comments explained: (U M T W R F S) maps to (Sun Mon ... Sat) # If it's MTWR, and past 2:11pm, display tomorrow. if ((grep {$dotw == $_} (1, 2, 3, 4)) && $time > 1411) { $day++ } # If it's SU, display M. elsif (grep {$dotw == $_} (6, 0)) { my $adj = $dotw / 6 + 1; $day += $adj; } # If it's F, and past 2:11pm, display M. elsif ($dotw == 5 && $time > 1411) { $day += 3 } print p($block_ref->[$day]); print p($event_ref->[$day]); print end_html; sub get_block { my (@blocks, @events); open (BLOCK, "block.db") or die "$!"; while (my $date = ) { chomp ($date); chomp ($blocks[$date] = ); chomp ($events[$date] = ); } close (BLOCK); return (\@blocks, \@events); }