Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Sorting Days of Week Using today () to today () + 6

by ww (Bishop)
on Jul 11, 2013 at 00:17 UTC ( #1043600=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Sorting Days of Week Using today () to today () + 6
in thread Sorting Days of Week Using today () to today () + 6

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.


Comment on Re^3: Sorting Days of Week Using today () to today () + 6
Select or Download Code
Re^4: Sorting Days of Week Using today () to today () + 6
by Hans Castorp (Acolyte) on Jul 11, 2013 at 12:32 UTC
    For now, I just want to say thank you--I need to "parse" this for awhile and I'll let you know how it goes. ;-)
Re^4: Sorting Days of Week Using today () to today () + 6
by Hans Castorp (Acolyte) on Jul 17, 2013 at 15:44 UTC

    Hi ww,

    Thank you very much--this does make a lot of sense (I've been trying to work through your examples and Cristoforo's suggestions since last week, but my deadline was coming up too fast and I ended up doing something quite different than the original script, which I'm going to post as a reply to my original question). Basically, I created a new table that included all the calendar dates, so I just needed to query one table. Now, my task is to write a Perl script that will populate my new table by querying the two other calendar tables!! ;-)

    Thank you so much for your patience and help. Cheers, HC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-19 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls