I am trying to place the date of each day of the week for each month
that has 5 weeks into a hash. For instance my hash key 'Monday' would
point to an array that has all the dates where Monday is in the fifth
week of the month.
I've got that part going. My problem is I am having a problem accessing
the hash. Data dumper shows me the data is there, but when I try to
access I am doing something wrong.

# cat fifthday
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw(Dumper);
use Time::Local;

        my @day_Array;
        @day_Array=qw{Monday Tuesday Wednesday Thursday Friday Saturday
Sunday};
        my $weekday;
        my %fifthday_hash;
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,
                $yday,$isdst)=localtime(time);
        my $today = sprintf ("%02d%02d%4d",$mon+1,$mday,$year+1900);
        $mon = $mon+1;
        $year +=1900;

        sub day_in_a_month; #predeclare
        sub day_in_a_month_driver; #predeclare
        foreach $weekday (@day_Array){
                print "this is weeekday $weekday\n";
                $fifthday_hash{$weekday} =
\day_in_month($weekday,$mon,$year);
        }

  print Dumper( \%fifthday_hash);
               while ( my ($key,$value)= each %{fifthday_hash} ) {
                        if ($key =~/Monday/) {
                        print "this is key =>$key<= $key $value\n";

                        }
               }



#***********************************************************************
*******
sub day_in_a_month_driver {
                my ($week_day, $month, $year ) = @_;
    my ($day, $hour, $min, $sec, $time);
    my ($mon, $wday_count, @date_arr);
    $day = 1;
    $hour = $min = $sec = 0;
    $month--;
    $year -= 1900;

    $time = timelocal($sec, $min, $hour, $day, $month, $year);

    for ($mon = $month; $mon == $month; $time += 86400) {
        my ($wday);
        ($day, $mon, $wday) = (localtime($time))[3,4, 6];
        if ($wday == $week_day) {
           $wday_count++;
                if ($wday_count == 5) {
                        $mon = $mon +1;
                        $year += 1900;
                        if ($day ne 1) {
                        return("$mon/$day/$year");
                        }
                }
        }
        else {next;}
    }
                        }#end day in month driver

#***********************************************************************
*******
sub day_in_month {
                my $start_day = shift;
                 if ($start_day =~/Sunday/ ) {
                        $start_day = 0;
                        }
                 elsif ($start_day =~/Monday/) {
                        $start_day =1;
                        }
                 elsif ($start_day =~/Tuesday/) {
                        $start_day = 2;
                        }
                 elsif ($start_day =~/Wednesday/) {
                        $start_day = 3;
                        }
                 elsif ($start_day =~/Thursday/) {
                        $start_day = 4;
                        }
                 elsif ($start_day =~/Friday/) {
                        $start_day = 5;
                        }
                 elsif ($start_day =~/Sat/) {
                        $start_day = 6;
                        }
                my $mon = shift;
                my $year = shift;
                my @rj=();
                my ($dateline,$dline);
                while ($year <= 2028) {
                for ($mon=$mon; $mon<=12; $mon++) {
                   $dline=day_in_a_month_driver($start_day, $mon,$year);
#                       print "this is dline $dline\n";
#                       if ( $dline !~ /^(\s)*$/) { #blank line
#                               return ($dline);
#                               }
           #     push (@rj, day_in_a_month_driver($start_day,
$mon,$year));
                push (@rj, $dline);
                }
                        $mon=1;
                        $year +=1;
                } #end while
                return(\...@rj);

                } #end day_in_month

Reginald Johnson



--------------------------------------------------------------------------
This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. The information contained in this 
e-mail was obtained from sources believed to be reliable; however, the accuracy 
or completeness of this information is not guaranteed. Unless specifically 
indicated, this message is not an offer to sell or a solicitation of any 
investment products or other financial product or service, an official 
confirmation of any transaction, or an official statement of Merrill Lynch. 
Subject to applicable law, Merrill Lynch may monitor, review and retain 
e-communications (EC) traveling through its networks/systems. The laws of the 
country of each sender/recipient may impact the handling of EC, and EC may be 
archived, supervised and produced in countries other than the country in which 
you are located. This message cannot be guaranteed to be secure or error-free. 
References to "Merrill Lynch" are references to any company in the Merrill 
Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America 
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are 
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal 
Government Agency. Past performance is no guarantee of future results. 
Attachments that are part of this E-communication may have additional important 
disclosures and disclaimers, which you should read. This message is subject to 
terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.
--------------------------------------------------------------------------
 

Reply via email to