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


In reply to Re: Re: Bottom-Up Data Mining with Perl by tachyon
in thread Bottom-Up Data Mining with Perl by rje

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.