Conal has asked for the wisdom of the Perl Monks concerning the following question:

hullo. I have a little perl script that gets the day from a MYSQL DATETIME. It looks like this.
use Date::Day; ## The following will print the weekday corresponding my $fragment = '2010-03-23 17:00:00'; $fragment = substr $fragment, 0, 10; my ( $year, $month, $day ) = split /-/, $fragment; $fragment = &day($month,$day,$year); $fragment = $fragment." $day-$month"; print "$fragment";
It works perfectly as expected. My problem is when i try to reuse it within a set of perl modules to write the day to a HTML file, it fails. the relevant section of code looks like this:
use Date::Day; ... my $fragment; if ($table =~ m/daily/) {$fragment = substr $ref->{'time'}, 0, 10; my ( $year, $month, $day ) = split /-/, $fragment; $fragment = &day($month,$day,$year); $fragment = $fragment." $day-$month"; } + else {$fragment = substr $ref->{'time'}, 11, 5;} + #write times to micro HTML printf MICROHTML '<td class="time">'; printf MICROHTML "$fragment"; printf MICROHTML '</td>';}
the $ref{'time'} is a variable used to store the MYSQL DATETIME and i know this is 100% working as i can dump out date info to HTML no problem, its when trying to use the Day method from Date::Day that i get a problem. The code is 'live' and runs on everyday at 5pm on a scheduled task so its hard for me to thouroghly debug the issue. I have been trying suss out what is wrong for a while now but cant put my finger on it. Can anyone help?
conal.

Replies are listed 'Best First'.
Re: Date::Day issues
by cdarke (Prior) on Mar 25, 2010 at 06:57 UTC
    it fails
    i get a problem

    How does it fail? What problem do you get? It could be that it cannot find the day subroutine, or the module, but that would be obvious from the error message, if you showed it.

    (By the way, why are you using printf? print is more efficient).
      OK. thanks for the reply. The problem is its just not writing the HTML file.. the code is obviously bombing out around where i introduce this code. I cant troubleshoot properly because i am adding the extra lines of code into something that is already live, It only runs once a day at 5pm. Its on a scheduled task and i cant read any errors msgs off the console. I guess i should try and create some kind of logfile.
      conal.

        The problem is its just not writing the HTML file..

        The printf in your code isn't conditional. If it was reached, it printed something out somewhere, or returned an error. Did it succeed or return an error? What error?

Re: Date::Day issues
by Marshall (Canon) on Mar 25, 2010 at 11:15 UTC
    Not sure what is wrong with your Perl code. However since you are using MySQL, this may be "re-inventing a wheel" as there is a function called DayName() in MySQL. Since you seem confident that the MySQL DATETIME is right, consider just asking MySQL to do the DayName conversion. SQL Date Time Functions