Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

by Hans Castorp (Sexton)
on Jul 10, 2013 at 18:37 UTC ( #1043532=note: print w/replies, xml ) Need Help??

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

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

  • Comment on Re^2: Sorting Days of Week Using today () to today () + 6

Replies are listed 'Best First'.
Re^3: Sorting Days of Week Using today () to today () + 6
by ww (Bishop) on Jul 11, 2013 at 00:17 UTC

    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\ 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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2016-10-25 02:45 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.