I probably would have converted the start/end month/day to GMT values and then iterated over them. Something like this:

#!/usr/bin/perl use warnings; use strict; use POSIX qw(strftime); use Time::Local; my @breakfast = qw/bagel cereal toast yogurt/; my @lunch = qw/sandwich milkshake pb&j hoagie/; my @dinner = qw/pasta rice chicken steak/; print "Enter start month (ie., for January, enter 1): "; chomp(my $start_mon = <STDIN>); print "Enter start day (ie., 20): "; chomp(my $start_day = <STDIN>); print "Enter end month (ie., for March, enter a 3): "; chomp(my $end_mon = <STDIN>); print "Enter end day (ie., 21): "; chomp(my $end_day = <STDIN>); print "Save to file [hit enter for default 'plan']: "; chomp(my $file = <STDIN>); $file ||= "plan"; my $start_gmt = timegm(0,0,0,$start_day,$start_mon-1,0); my $end_gmt = timegm(0,0,0,$end_day,$end_mon-1,0); open(FH, ">$file") or die "open: $!\n"; for (my $g = $start_gmt; $g <= $end_gmt; $g += 86400) { print FH my $d = strftime("%b %e", gmtime($g)), "\n"; print "-" x length($d), "\n"; print FH "Breakfast: $breakfast[rand @breakfast]\n"; print FH "Lunch : $lunch[rand @lunch]\n"; print FH "Dinner : $dinner[rand @dinner]\n"; print "-" x length($d), "\n"; } print "Written to file $file.\n"; close(FH);

There are all sorts of modules on CPAN dealing with dates and times that could have helped you out too.


In reply to Re: Critique by duff
in thread Critique by phenom

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.