Gossamer Forum
Home : General : Perl Programming :

Seeing double!

Quote Reply
Seeing double!
Anyone see why this is printing out;

Quote:
The 5th is the first Sunday of Jan
The 12nd is the second Sunday of Jan
The 19th is the third Sunday of Jan
The 26th is the fourth Sunday of Jan

The 5th is the first Sunday of Jan
The 12nd is the second Sunday of Jan
The 19th is the third Sunday of Jan
The 26th is the fourth Sunday of Jan

when calling;

Code:
$call_months[0]

The code I'm using is;

Code:
# now search the date stuff, and format the table...
my $year = 2003;
my @months = ( ['Jan' => 31], ['Feb' => ($year % 4 ? 28 : 29)], ['Mar' => 31], ['Apr' => 30],
['May' => 31], ['Jun' => 30], ['Jul' => 31], ['Aug' => 31],
['Sep' => 30], ['Oct' => 31], ['Nov' => 30], ['Dec' => 31],
);

my @call_months = qw();

my @ordinal = qw(first second third fourth fifth);
my @ends = ('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th');

foreach my $n (0..$#months) {

my $date = ParseDate("1st Sunday in $months[$n][0] $year");
my ($day) = $date =~ /^\d{6}(\d\d)/;
my $i = 0;
while ($day <= $months[$n][1]) {
$call_months[$n] .= sprintf("The %2d@ends[$day=~/(\d)$/] is the $ordinal[$i] Sunday of $months[$n][0]<BR>", $day);
$day += 7; $i++;
}
}

I can't see the fault in the code Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Seeing double! In reply to
Wow, you enjoy making life difficult for yourself. You do know that modules exist that do this for you, right?

- wil
Quote Reply
Re: [Wil] Seeing double! In reply to
What, that gives me the beginning date of each week, and the month name?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Seeing double! In reply to
Looked into Date::Calc?

- wil
Quote Reply
Re: [Wil] Seeing double! In reply to
Actually, after looking again, it might even be simpler using Time::Local.

- wil