Here is a much better data structure that also shows you how you can set a hash value to the return val of a sub and thus give feb a correct value. It also shows semi dynamic hash construction using map FWIW.
my @month_names = qw( undef, jan feb mar apr may jun jul aug sept oct
+nov dec );
my @month_days = ( undef, 31, &feb_days, 31, 30, 31, 30, 31, 31, 30, 3
+1, 30, 31 );
my $months = {
name => { map{ $_, $month_names[$_]} 1..12 },
number => { map{ $month_names[$_], $_ } 1..12 },
days => { map{ $_, $month_days[$_], $month_names[$_], $month_day
+s[$_] } 1..12 },
};
print "Month number 4 is ", $months->{name}->{4}, "\n";
print "Month mar is number ", $months->{number}->{mar}, "\n";
print "Days in month feb ", $months->{days}->{feb}, "\n";
print "Days in month 4 ", $months->{days}->{4}, "\n";
use Data::Dumper;
print Dumper $months;
sub feb_days { check_leap_year( get_year() ) ? 29 : 28 }
sub get_year { (localtime())[5] + 1900 }
sub check_leap_year {
my $year = shift;
my $leap_year = 0;
$leap_year = 1 if $year % 4 == 0;
$leap_year = 0 if $year % 100 == 0 and $year % 400 != 0;
return $leap_year;
}
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print