in reply to Re: Error from timelocal
in thread Error from timelocal

"Getting a date with Perl" may be the most misleading title since "Naked Lunch". It's Friday night, and despite (or because of) my skill with Perl, I still have the same problem as before: no date. If Perl could help people get dates, C would be deader than Pascal and Larry Wall would be richer than Bill Gates.

-Logan
"What do I want? I'm an Perl Coder. I want more dates."

Replies are listed 'Best First'.
In defence of merlyn...
by jonnyfolk (Vicar) on Dec 21, 2002 at 09:42 UTC
    From my reading of the problem, mkent simply has a problem translating the variables in his file with Time::Local.

    Reproducing merlyn's article we get:

    #!/usr/bin/perl -w use strict; use CGI ':standard'; use Time::Local; my $time = timelocal(0,0,0,1,0,100); my $string = localtime $time; print header(), start_html(-title => ""); print "the big ball falls at $time => $string\n"; print end_html();
    Simply placing the mkent's line:
    my $time = timelocal($sec,$min,$hhour,$day,$month,$year);
    should work in the same way provided MarkM's advice is followed:
    my $time = timelocal($sec,$min,$hhour,$day,$month-1,$year-=1900);
    So finally we have:
    #!/usr/bin/perl -w use strict; use CGI ':standard'; use Time::Local; my $sec = "50"; my $min = "20"; my $hhour = "10"; my $day = "12"; my $month = "12"; my $year = "2002"; my $time = timelocal($sec,$min,$hhour,$day,$month-1,$year-=190 +0); my $string = localtime $time; print header(), start_html(-title => ""); print "the big ball falls at $time => $string\n"; print end_html();
    The truth is in there. Somewhere.