#!perl -w

use strict;
no strict "vars";

use Date::DateCalc qw(day_name_tab month_name_tab date_to_string);

use Date::DateCalcLib qw(nth_wday_of_month_year);

$n = shift;
$wday = shift;
$month = shift;
$year = shift;

%ordinal = ( 1 => '1st', 2 => '2nd', 3 => '3rd' );

if (($yy,$mm,$dd) = nth_wday_of_month_year($n,$wday,$month,$year))
{
    $nth = $ordinal{$n} ? $ordinal{$n} : $n . "th";

    print "The $nth ", day_name_tab($wday), " in ", month_name_tab($month),
      " $year is ", date_to_string($yy,$mm,$dd), "\n";
}
else
{
    die "Invalid entries! Please try again.\n";
}

__END__

