Hey guys, I am using information from last, and the output looks like this:

"daamaya pts/3055 10.37.48.88 Thu Sep 18 09:19 still logged in"

I am basically trying to write a script that will look at the date "Thu Sep 18" and give me the year. I know that the 18th was not on a Thursday in 2007, and so on. I am only doing it between 2004-2008. I wrote a little script that kinda does what I am looking for, but trying to figure out how to make it a subroutine, and how to do it better. I am relatively new to hashes, which would explain why I added a,b,c... to the front of months, just for sorting reasons. Anyway, here's my code. Any suggestions would be so greatly appreciated!!

#!/usr/bin/perl -w print "Please input a year: "; chomp ($year=<STDIN>); $k = 0; while ($year <= 2008) { if (($year % 4 == 0) and ($year % 100 != 0) or ($year % 400 == 0)) + { $leap="true"; } else { $leap="false"; } my %months = ( 'aJan' => '31', 'bFeb' => '28', 'cMar' => '31', 'dApr' => '30', 'eMay' => '31', 'fJun' => '30', 'gJul' => '31', 'hAug' => '31', 'iSep' => '30', 'jOct' => '31', 'kNov' => '30', 'lDec' => '31' ); if ($leap eq "true") { $months{'bFeb'} = '29'; } my @array_of_days = ('Thu', 'Fri', 'Sat', 'Sun', 'Mon', 'Tue', 'We +d'); # my $start = $weekdays{$day_name}; foreach $key (sort keys %months) { #print(join(', ',sort keys %months),"\n"); for ($n = 1; $n <= $months{$key}; $n++) { if ($k == 7) { $k = 0; } print "$array_of_days[$k] $key $n $year\n"; $k++; } } $year++; }

In reply to Question, New To Hashes by walkingthecow

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.