Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems returning values in DATE::CALC module 1

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
0
0
US
Hello,
I am probably doing something silly in this script but here it goes.

I am having a problem returning the day_of_week value when using a DATE::CALC module function. When I comment the function call out all the data prints but when I uncomment it just the header prints. I am able to print the $month $day $year variables within the print statement.

At any rate I am unable to obtain the "day of the week" for any given standard date.

Any suggestions

It is a short script but it is all there.The DB file is on the bottom.

Thanks
Tim

###################### CGI CODE BELOW #####################

Code:
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
use CGI qw(:standard);
use Date::Calc qw(Day_of_Week Week_Number Day_of_Year);


my $db ="data/events.txt";

open (FILE, &quot;<&quot; . $db) || die &quot;Well, whats up.. cant open file&quot;;


#flock (FILE, 2 );

my $lc = 0;

print header();
print start_html(-title=>'Script');
print h2('Upcoming Parish Events!<a href=&quot;[URL unfurl="true"]http://www.martin.com/cgi-local/homepage_update/events/post_events.cgi&quot;>[/URL]
<BR>UPDATE UPCOMING PARISH EVENTS</a><BR><HR>');
while (<FILE>)
{
my $line = $_;
$line =~ s/\n$//;
my @events = split (&quot;::&quot;, $line);

if ($events[1] eq &quot;&quot;){$lc = $line};
$lc ++;
my $year =  $events[4];
my $month = $events[1];
my $day =   $events[2];
#my $weekday = Day_of_Week($year, $month,$day);
#print &quot;$month/$day/$year was a &quot;, Day_of_Week_to_Text($weekday), &quot;\n&quot;;
Code:
print&quot; $month $day $year 

<TABLE width='100%' border='0' cellspacing='0' cellpadding='0'> 
 <tr align='left' valign='top' bgcolor='#669999'>
<td width='339' height='15' bgcolor='#cc99cc'>
<font size='2'>
<b>
<FONT face=arial color='#000000'> 

</FONT><font color='#000000' face='Verdana, Arial, Helvetica, sans-serif' size='2'>
                        - 
</font><FONT face=arial color='#000000'>
$events[1]
</FONT>
<font color='#000000' face='Verdana, Arial, Helvetica, sans-serif' size='2'>
                        
</font><FONT face=arial color='#000000' size=2>
$events[2]
</FONT>  
<font face='Verdana,Arial,Helvetica,sans-serif' color='#000000'>
$events[4]
</font>
</b>
</font>
</td>
</tr>
    
<tr align='left' valign='top' bgcolor='#669999'>
<td width='339' height='15' bgcolor='#FFFFFF'>
<FONT face='Arial narrow,Helvetica,Verdana,sans-serif'color='#000000'>
<B>
<FONT size=2>
$events[5]
</FONT>
</B>
</FONT>
                        
<FONT face='Verdana, Arial, Helvetica, sans-serif' size=1>
$events[6]
</FONT>
                      
</td>                    
</tr>

</TABLE>

&quot;;[/color]
[/color]


if ($events[1] eq &quot;&quot;){
#flock (FILE, 8 );
close (FILE);
}
print end_html();
}
######################   events.txt file  ################
1054047381::Jun::14,::Sat::2003::ANNUAL DINNER DANCE<BR>presented by FIL_AM::The FIL-AM ASSOCIATION of St Martin invites you to our annual Independence Day dinner/dance celebration. Great food, entertainment, dancing and raffle tickets. $600 total cash & fabulous prizes.<BR>Please contact Moria Kang at 921-5912 for more info.
1050616643::Jun::18,::Wed::2003::SCRIPTURE SHARING<BR>::We invite you to share each Wednesday morning in prayer and reflection on the Scriptures. Sessions are 9:30am - 11:00am in the Cottrell Center. For more information<BR>email <a href=&quot;mailto:PatriceU7123@aol.com&quot;>Patrice Underwood</a> or call at 736-3725 ext:11</B>
1051234044::Jun::19,::Thu::2003::SENIOR TRIP    <Font color ='red'>9:00AM - 4:00PM</font color>::<BR>We invite you to join a popular tour of five different churches:The Swedenborgian Church, a lovely country-styled church;The Buddhist Church, with its stunning altar; The Greek Orthodox Cathedral of the Annunciation where the group will have lunch; The Old First Presbyterian Church, now the oldest Protestant Church in California; and St. Peter and Paul’s National Italian Church that is awesome. Cost: tour, bus fare, and lunch - $42.00 per person. Call Jackie at the Parish Office, 736-3725 or stop by during office hours. 
1051234038::Oct::10,::Sat::2003::St. Martin International Festival::<BR>On Saturday, October 10, you are invited to share in the annual St. Martin Parish International Festival. 
1051234039::Oct::11,::Sun::2004::St. Martin International Festival::<BR>On Sunday, October 11, you are invited to share in the annual St. Martin Parish International Festival.
 
Two problems: your day is picking up a trailing comma and your month is textual rather than numeric. The following runs on my system:
Code:
#!/usr/bin/perl

use Date::Calc qw(:all);

my $line = '1054047381::Jun::14,::Sat::2003::ANNUAL DINNER DANCE<BR>presented by FIL_AM::The FIL-AM ASSOCIATION of St Martin invites you to our annual Independence Day dinner/dance celebration. Great food, entertainment, dancing and raffle tickets. $600 total cash & fabulous prizes.<BR>Please contact Moria Kang at 921-5912 for more info.';

my @events = split (&quot;::&quot;, $line);

my $year =  $events[4];
my $month = $events[1];
my $day =   $events[2];

print &quot;day=$day, month=$month, year=$year\n&quot;;

$day=~ s/,//;

my %MonthNum = (
        Jan => 1,        Feb => 2,        Mar => 3,
        Apr => 4,        May => 5,        Jun => 6,
        Jul => 7,        Aug => 8,        Sep => 9,
        Oct => 10,       Nov => 11,       Dec => 12,
);

$month = $MonthNum{$month};

my $weekday = Day_of_Week($year, $month,$day);
print &quot;$month/$day/$year was a &quot;, Day_of_Week_to_Text($weekday), &quot;\n&quot;;

and prints

Code:
day=14,, month=Jun, year=2003
6/14/2003 was a Saturday
which it will have been was by past then (?)

PS: check out Date::parse for parsing arbitrary dates or Time::Local to convert simple dates (as above) and then use localtime to get things like the day of the week.


Yours,


fish

&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top