You're storing (Ln 62) "normal hours data in hash of hashes." But you already have that data in a perfectly good array, namely @row (Ln 57-60) as fetched from the db. You can code your html production such that the "current" day is found by its offset -- a dispatch table, for one possibility. The order of the array's elements will be the order you coded in 59-60.
But when you talk about using Data::Dumper to look at the structure, I have to suspect you're dumping your hash. To keep it simple, be aware that hashes determine their own internal ordering, which means that what you get back will have to be sorted to some other (your choice) order. But arrays don't give you that sorting requirement. Given your @row, $tuesday_openhour will always be $row[7] :
#!/usr/bin/perl
use 5.016;
# 1043504
my $sunday_open = 0; # element 0 of @row, or $row[0]
my $sunday_openhour = 0;
my $sunday_closehour = 0;
my $monday_open = 1; # element 3 of @row, or $row[3]
my $monday_openhour = 7;
my $monday_closehour = 5;
my $tuesday_open = 1; # !!! change to 0 to see the effect;
# then back to 1 for a normal Tuesday wo
+rkday
my $tuesday_openhour = 7; # element 7 of @row, or $row[7]
my $tuesday_closehour = 5;
my $wednesday_open = 1;
my $wednesday_openhour = 7;
my $wednesday_closehour = 9;
my $thursday_open = 1;
my $thursday_openhour = 7;
my $thursday_closehour = 5;
my $friday_open = 1;
my $friday_openhour = 7;
my $friday_closehour = 5;
my $saturday_open = 1;
my $saturday_openhour = 9;
my $saturday_closehour= 2; # element 20 of @ row or $row[20]
my @row = ( $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,
);
say " FOR ILLUSTRATION: The var at \$row[7] will always be the sevent
+h element\n of \@row (array element counting starts at zero)\n and th
+e content of that var is $row[7], the value assiged in your hours_arr
+ay to \$tuesday_openhour. \n";
if ($row[6] == 1 ) {
say " We're open on Tuesday, starting at $row[7]a.m. until $row[8]
+p.m.";
}elsif ($row[6] == 0) {
say " Sorry, we won't be open today.\n But if you'd like to come i
+n on Saturday, do so between $row[19]a.m. and $row[20]p.m.";
}else {
say "oops!";
}
=head
C:\Users\wheelerw>D:\_Perl_\PMonks\1043504.pl
FOR ILLUSTRATION: The var at $row[7] will always be the seventh elem
+ent
of @row (array element counting starts at zero)
and the content of that var is 7, the value assiged in your hours_arr
+ay to $tuesday_openhour.
We're open on Tuesday, starting at 7a.m. until 5p.m.
=cut
Hope this clarifies what I failed to communicate previously.
If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
|