Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
We don't bite newbies here... much
 
PerlMonks  

Re: how can i find number of days in a given year and month

by davorg (Chancellor)
on Jul 17, 2001 at 08:15 UTC ( [id://97267]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to how can i find number of days in a given year and month

You can achive this without using external modules:

#!/usr/bin/perl -w use strict; use Time::Local; while( <DATA> ) { chomp; my ($year, $month) = split; do { warn "Invalid month: $month\n"; next } if $month > 12 or $month < 1; my $next_year = ($month == 12) ? $year + 1 : $year; my $next_month = timelocal(0, 0, 0, 1, $month % 12, $next_year); my $days = (localtime($next_month - 86_400))[3]; print "$year/$month => $days\n"; } __DATA__ 1996 1 1996 2 1998 2 2000 2 1900 2 1600 2 2001 2 2001 7 2001 12 2001 13 2001 0

Update: Small fixes to code as recommended by tye

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://97267]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.