Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

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


in reply to Sorting Days of Week Using today () to today () + 6

It may be that I took one too many stupid pills this am but I really don't understand why you "think that what (you) need to do is sort (your) normal hours according to ..." ...DOW. It appears that you expect the db to cough up the row with reasonable sorting ... Sun-Sat... and the biz hours row to do likewise so your requirement is merely that you select today's DOW as your starting point in each case and proceed thru DOW + 6.

And, without working out the details, numerous questions on mergine two arrays; on dispatch tables; or perhaps slices would spare a lot of unnecessary work.

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.


If you didn't program your executable by toggling in binary, it wasn't really programming!


Comment on Re: Sorting Days of Week Using today () to today () + 6
Re^2: Sorting Days of Week Using today () to today () + 6
by Hans Castorp (Acolyte) on Jul 10, 2013 at 18:37 UTC

    Thank you for your response ww--I am trying to understand what you are telling me....

    I've done a Data::Dumper::Dump for the normal hours, so I've seen that the output is not organized in any meaningful way. Nevertheless, when the script runs and the html file is generated, it is always Sunday-Saturday.

    What I'm trying to figure out is how to get the data to put out an html file that is the current dow - dow + 6--I'm not sure where in the script I begin to address this.

    The reason I'm having trouble is, the normal hours table does not have dates--it's strictly Sun - Sat. The exception hours table has dates, so it's easy to specify in the SQL the dates I want.

    Forgive if I seem clueless--it's because, largely, I am, when it comes to programming. I'm doing my best to figure it out, but it's not the bulk of my job by a long shot. (More like sporadically being thrown in deep water and figuring out how to swim.)

      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.
        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. ;-)

        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://1043515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-08-20 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (120 votes), past polls