#!/usr/bin/perl use warnings; use strict; my %months = ( 1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "June", 7 => "July", 8 => "Aug", 9 => "Sept", 10 => "Oct", 11 => "Nov", 12 => "Dec" ); my @breakfast = qw/bagel cereal toast yogurt/; my @lunch = qw/sandwich milkshake pb&j hoagie/; my @dinner = qw/pasta rice chicken steak/; my $file = ''; my ($start_day, $start_mon, $end_day, $end_mon); my ($total, $len, $curr_mon, $curr_day); my $three_one = join ('|', qw/1 3 5 7 8 10 12/); #months with 31 days my $three_zero = join ('|', qw/4 6 9 11/); #months with 30 days print "Enter start month (ie., for January, enter 1): "; chomp($start_mon = ); print "Enter start day (ie., 20): "; chomp($start_day = ); print "Enter end month (ie., for March, enter a 3): "; chomp($end_mon = ); print "Enter end day (ie., 21): "; chomp($end_day = ); print "Save to file [hit enter for default 'plan']: "; chomp($file = ); if($file eq '') { $file = "plan"; } open(FH, ">$file") or die "open: $!\n"; $curr_mon = $start_mon; $curr_day = $start_day; $total = get_days(); # get # of days for the current month while (1) { last if($curr_mon eq $end_mon && $curr_day == $end_day + 1); print FH "$months{$curr_mon} $curr_day\n"; $len = length($months{$curr_mon}) + length($curr_day) + 1; print FH "-" x $len, "\n"; print FH "Breakfast: ", $breakfast[ rand @breakfast], "\n"; print FH "Lunch : ", $lunch[ rand @lunch], "\n"; print FH "Dinner : ", $dinner[ rand @dinner], "\n"; print FH "-" x $len, "\n"; $curr_day++; if($curr_day > $total) { $curr_mon++; $curr_day = 1; $total = get_days(); } } print "Written to file $file.\n"; close(FH); sub get_days { if($curr_mon =~ /$three_one/) { return 31; } elsif($curr_mon =~ /$three_zero/) { return 30; } elsif($curr_mon == 2) { return 29; } else { die "Bad month entered!\n"; } }