# -- define today my $today = today(); # -- use today object and return a number indicating the current day of week (0=sun 1=mon, etc.) my $dow = $today->day_of_week; # -- get the start and end dates for the week # -- Date module helps us do this easily my $today_date = ( $today ); # start of week my $end_date = ( $today_date + 6 ); # end of week # -- will store data for Sun <-> Sat with day of week (number) as key my %this_wk = (); # -- simple arrays to define days my @days = (0 .. 6); my @day_text = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); # -- loop thru all days of week and add data to hash # -- we will add more data to hash later for my $day (@days) { # -- add date and day text identifier to hash $this_wk{$day}{date} = ( $today_date + $day ); $this_wk{$day}{day_text} = $day_text[$day]; } ## end days for loop # -- connect to Voyager db my $dbh = DBI->connect( $voy_dsn,$voy_dbun,$voy_dbpass, { AutoCommit => 0, RaiseError => 0, PrintError => 1 } ) || die $DBI::errstr; # -- get normal hours of operations # -- yes, believe it or not there is only one row (there must be a reason for this setup but I can't think of one) my $sql = qq(SELECT sunday_open,sunday_openhour,sunday_closehour, monday_open,monday_openhour,monday_closehour, tuesday_open,tuesday_openhour,tuesday_closehour, wednesday_open,wednesday_openhour,wednesday_closehour, thursday_open,thursday_openhour,thursday_closehour, friday_open,friday_openhour,friday_closehour, saturday_open,saturday_openhour,saturday_closehour FROM calendar WHERE calendar_desc = '$voy_cal2use'); my $sth = $dbh->prepare( $sql ); $sth->execute; # -- fetch all data and create var to refer to my $arrayref_norm_hrs = $sth->fetchall_arrayref( ); # -- store normal hours for each day of week in here my %normal_hrs = (); # -- loop thru the data array returned by query # -- put in a data structure we can work with foreach my $row ( @$arrayref_norm_hrs ) { my ( $sun_open,$sun_openhr,$sun_closehr,$mon_open,$mon_openhr,$mon_closehr, $tue_open,$tue_openhr,$tue_closehr,$wed_open,$wed_openhr,$wed_closehr, $thu_open,$thu_openhr,$thu_closehr,$fri_open,$fri_openhr,$fri_closehr,$sat_open,$sat_openhr,$sat_closehr ) = @$row; # -- store normal hours data in hash of hashes $normal_hrs{$days[0]}{openorclosed} = $sun_open; $normal_hrs{$days[0]}{open} = $sun_openhr; $normal_hrs{$days[0]}{close} = $sun_closehr; $normal_hrs{$days[1]}{openorclosed} = $mon_open; $normal_hrs{$days[1]}{open} = $mon_openhr; $normal_hrs{$days[1]}{close} = $mon_closehr; $normal_hrs{$days[2]}{openorclosed} = $tue_open; $normal_hrs{$days[2]}{open} = $tue_openhr; $normal_hrs{$days[2]}{close} = $tue_closehr; $normal_hrs{$days[3]}{openorclosed} = $wed_open; $normal_hrs{$days[3]}{open} = $wed_openhr; $normal_hrs{$days[3]}{close} = $wed_closehr; $normal_hrs{$days[4]}{openorclosed} = $thu_open; $normal_hrs{$days[4]}{open} = $thu_openhr; $normal_hrs{$days[4]}{close} = $thu_closehr; $normal_hrs{$days[5]}{openorclosed} = $fri_open; $normal_hrs{$days[5]}{open} = $fri_openhr; $normal_hrs{$days[5]}{close} = $fri_closehr; $normal_hrs{$days[6]}{openorclosed} = $sat_open; $normal_hrs{$days[6]}{open} = $sat_openhr; $normal_hrs{$days[6]}{close} = $sat_closehr; } ## end normal hours data foreach loop