2010/1/17 Johnson, Reginald (GTS) <reggie.john...@bankofamerica.com>:
> 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.


It looks like you have gone to a lot of effort but I fear that you
might be trying to re-invent the wheel here. The DateTime family of
modules will probably do all you need. It also has it own site with
useful FAQs. http://datetime.perl.org/?FAQ the SampleCalculations
section looks relevant to you needs.

As for the accessing the value of $fifthday_hash{Monday}, you appear
to have tried to create a subroutine reference for each key.  I
modified it a bit to see what was going on but I didn't want to spend
too much time on it for the reasons stated above;

       #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} = sub
{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";
                       my $val = $value->($key,1 , 2010);
                       print "Val=".join ', ',@$val,"\n
.....

We I ran the above I get this. Not sure if that what you expected.

this is weeekday Monday
this is weeekday Tuesday
this is weeekday Wednesday
this is weeekday Thursday
this is weeekday Friday
this is weeekday Saturday
this is weeekday Sunday
this is key =>Monday<= Monday CODE(0x83c5ce8) CODE
Val=, , 3/29/2010, , 5/31/2010, , , 8/30/2010, , , 11/29/2010, ,
1/31/2011, , , , 5/30/2011, , , 8/29/2011, , 10/31/2011, , ,
1/30/2012, , , 4/30/2012, , , 7/30/2012, , , 10/29/2012, , 12/31/2012,
, , , 4/29/2013, , , 7/29/2013, , 9/30/2013, , , 12/30/2013, , ,
3/31/2014, , , 6/30/2014, , , 9/29/2014, , , 12/29/2014, , ,
3/30/2015, , , 6/29/2015, , 8/31/2015, , , 11/30/2015, , , 2/29/2016,
, , 5/30/2016, , , 8/29/2016, , 10/31/2016, , , 1/30/2017, , , ,
5/29/2017, , 7/31/2017, , , 10/30/2017, , , 1/29/2018, , , 4/30/2018,
, , 7/30/2018, , , 10/29/2018, , 12/31/2018, , , , 4/29/2019, , ,
7/29/2019, , 9/30/2019, , , 12/30/2019, , , 3/30/2020, , , 6/29/2020,
, 8/31/2020, , , 11/30/2020, , , , 3/29/2021, , 5/31/2021, , ,
8/30/2021, , , 11/29/2021, , 1/31/2022, , , , 5/30/2022, , ,
8/29/2022, , 10/31/2022, , , 1/30/2023, , , , 5/29/2023, , 7/31/2023,
, , 10/30/2023, , , 1/29/2024, , , 4/29/2024, , , 7/29/2024, ,
9/30/2024, , , 12/30/2024, , , 3/31/2025, , , 6/30/2025, , ,
9/29/2025, , , 12/29/2025, , , 3/30/2026, , , 6/29/2026, , 8/31/2026,
, , 11/30/2026, , , , 3/29/2027, , 5/31/2027, , , 8/30/2027, , ,
11/29/2027, , 1/31/2028, , , , 5/29/2028, , 7/31/2028, , , 10/30/2028,
, ,


Good luck,
Dp.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to