in reply to Time::ParseDate issues

When the script runs at the top of the hour ("00"), the value for $min is 0. Have you verified that parsedate() isn't bothered by a time that looks like "2:0:00"?

In any case, this:

parsedate($hour.":".$min.":00")
could be replaced with $now after adding the following lines before the while:
my $now = time; $now -= ($now % 60);

Replies are listed 'Best First'.
Re^2: Time::ParseDate issues
by spmlingam (Scribe) on Nov 27, 2008 at 11:24 UTC
    The parsedate function will return undef value, if the time format is not correct.
    The time format is hh:mm:ss.
    You can add the digit zero in front of hour and minute.
    You can use the following code:
    $min = "0".$min if(length($min) == 1); $hour= "0".$hour if(length($hour) == 1);
Re^2: Time::ParseDate issues
by Conal (Beadle) on Nov 28, 2008 at 13:39 UTC
    hi eye, thanks for replying with this. i have tried a number of solutions here and yours seems the most likely. fixing up $hour and $min so it is in a format that doesnt make Parsedate return undef still produces an issue at 00:00:00. i have a problem tho, what is this code doing exactly and why does it work?
    my $now = time; $now -= ($now % 60);
    and also would it work if i wanted to run my code every 5minutes with similar data, as opposed to 30minutes? thanks for your input and sorry to be a pain.
    conal.
      parsedate($hour.":".$min.":00"))

      should give the same number of seconds,(since Jan 1, 1970), as:

      my $now = time; $now -= ($now % 60);

      I say should because I don't know if the function parsedate gives seconds since the epoch when only supplied the time numbers (and not the date numbers).

      What his code is doing is removing any seconds (> 00)

      Chris

        Yes Time::ParseDate does resolve to the number of seconds since jan 1 1970, even if only hours and minutes and seconds are sent to the function.

        'The return code is always the time in seconds since January 1st, 1970 or undef if it was unable to parse the time.'

        http://search.cpan.org/~muir/Time-modules-2003.0211/lib/Time/ParseDate.pm#DESCRIPTION

        I believe thats it pretty much sussed now. thanks everyone ever so much. its much appreciated.
        conal.