Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Lately I have been using a particular set of code over and over again, and I finally decided to put it into a module. I would like everyone's overall opinion of this code, and whether or not they think it might even be worthy of CPAN.
package Date::Lastday; $VERSION=0.01; use strict; ## GLOBALS ## my %Max_Days=("Jan"=>"31","Feb"=>"28","Mar"=>"31","Apr"=>"30", "May"=>"31","Jun"=>"30","Jul"=>"31","Aug"=>"31", "Sep"=>"30","Oct"=>"31","Nov"=>"30","Dec"=>"31"); my %Months=("01"=>"Jan","02"=>"Feb","03"=>"Mar","04"=>"Apr", "05"=>"May","06"=>"Jun","07"=>"Jul","08"=>"Aug", "09"=>"Sep","10"=>"Oct","11"=>"Nov","12"=>"Dec"); ## Functions ## sub new{ my $self=shift; return bless {} $self; } sub last{ my $self=shift; my ($Day,$Month,$Year)=(localtime)[3,4,5]; $Month=sprintf("%02d,($Month+1)); $Year=sprintf("%04d,($Year+1900)); ## Provide for leap years ## my $Leap=$Year % 4; if($Leap==0){ $Max_Days{"Feb"}=29; } if($Day==1 and $Month==1){ # Cover January 1st $Month=12; $Day=31; $Year=$Year-1; }elsif($Day==1){ # Cover the 1st of any month $Month-=1; $Month=sprintf("%02d",$Month); $Day=$Max_Days{$Months{$Month}}; }else{ $Day-=1; $Day=sprintf("%02d",$Day); } return $Month,$Day,$Year; } sub cal{ my $self=shift; my ($Day,$Month,$Year)=(localtime)[3,4,5]; $Month=sprintf("%02d,($Month+1)); $Year=sprintf("%04d,($Year+1900)); ## Provide for leap years ## my $Leap=$Year % 4; if($Leap==0){ $Max_Days{"Feb"}=29; } if($Day==1 and $Month==1){ # Cover January 1st $Month="Dec"; $Day=31; $Year=$Year-1; }elsif($Day==1){ # Cover the 1st of any month $Month-=1; $Month=sprintf("%02d",$Month); $Month=$Months{$Month}; $Day=$Max_Days{$Months}; }else{ $Day-=1; $Day=sprintf("%02d",$Day); $Month=$Months{$Month}; } return $Month,$Day,$Year; } 1; __END__; =pod =head1 NAME Date::Lastday - Perl extension to calculate previous day's date =head1 SYNOPSIS use Date::Lastday; my $Last=new Date::Lastday; my ($Month,$Day,$Year)=$Last->last(); ## OR ## my ($Month,$Day,$Year)=$Last->cal(); =head1 DESCRIPTION Date::Lastday is used to calculate the date of the previous day. It us +es the localtime function of Perl to get the date, then manipulate it + from there. The last function returns the month and day as 2 digit numbers, and th +e year as a 4 digit number. If you wish to have the month returned as + the 3 letter abbreviation (i.e. Jan, Feb, Mar, etc.), use the cal fu +nction. =head2 EXPORT None by default =head1 AUTHOR Thomas Stanley =head1 COPYRIGHT Copyright (C) 2001 Thomas Stanley. All rights reserved. This program i +s free software; you can redistribute it and/or modify it under the s +ame terms as Perl itself. =head1 SEE ALSO perl(1) =cut

There's an infinite number of monkeys outside who want to talk to us
about this script for Hamlet they've worked out
-- Douglas Adams/Hitchhiker's Guide to the Galaxy

In reply to Module Code Review by TStanley

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (2)
    As of 2019-02-16 04:56 GMT
    Find Nodes?
      Voting Booth?
      I use postfix dereferencing ...

      Results (95 votes). Check out past polls.