I think you want today plus the next 6 days with the day of week for each of the days. If so, then the code below will do that.
#!/usr/bin/perl use strict; use warnings; use 5.014; use Date::Simple qw/ today /; my @day_text = qw(Sunday Monday Tuesday Wednesday Thursday Friday Satu +rday); my $dow = today->day_of_week; my @in_order = map {$_ % 7} $dow .. $dow + 6; say "localtime is: " . localtime; say "$_ $day_text[$_]" for @in_order; __END__ *** results of running the program C:\Old_Data\perlp>perl t5.pl localtime is: Wed Jul 10 16:10:33 2013 3 Wednesday 4 Thursday 5 Friday 6 Saturday 0 Sunday 1 Monday 2 Tuesday
Update: The same without need for the @day_text array. Can get the day names right from Date::Simple.
my $today = today; my @names = map { ($today + $_)->strftime("%A")} 0 .. 6; my $dow = today->day_of_week; my @in_order = map {$_ % 7} $dow .. $dow + 6; say "localtime is: " . localtime; say $in_order[$_], ' ', $names[$_] for 0 .. $#in_order;
The hash, %normal_hrs, could then be accessed like this sample code.
my $today = today; my @names = map { ($today + $_)->strftime("%A")} 0 .. 6; my $dow = $today->day_of_week; my @in_order = map {$_ % 7} $dow .. $dow + 6; my $today_dow = shift @in_order; my $today_name = shift @names; # using a hash slice my @today_info = @{ $normal_hrs{$today_dow} }{qw/ openorclosed open cl +ose /}; # write today's info to html # drop down list for my $dow (@in_order) { my $day_name = shift @names; # using a hash slice my @info = @{ $normal_hrs{$dow} }{qw/ openorclosed open close /}; # write this day's info to drop down list }
Update: For a little cleaner code, I put the contents of the 2 arrays, (@dow and @names into an array of hashes to more safely access the data below - less chance of an error.
my $today = today; my @names = map { ($today + $_)->strftime("%A")} 0 .. 6; my $dow = $today->day_of_week; my @dow = map {$_ % 7} $dow .. $dow + 6; my @data; for my $i (0 .. 6) { push @data, {dow => $dow[$i], name => $names[$i]}; } my $date = shift @data; # using a hash slice for today's info # You have access to $date->{dow} and $date->{name} my @today_info = @{ $normal_hrs{ $date->{dow} } }{qw/ openorclosed ope +n close /}; # write today's info to html # drop down list for my $date (@data) { # You have access here to $date->{dow} and $date->{name} # using a hash slice my @info = @{ $normal_hrs{$date->{dow}} }{qw/ openorclosed ope +n close /}; # write this day's info to drop down list }

In reply to Re: Sorting Days of Week Using today () to today () + 6 by Cristoforo
in thread Sorting Days of Week Using today () to today () + 6 by Hans Castorp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.