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

******************
FIXED - thanks to wfsp
******************

hello please can you help
i am trying to get the elements of the gmtime return by
using this
#!c:/perl/bin/perl use Time::gmtime; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(); print << "EOF"; Content-Type: Text/html\n\n <b><font face=courier color=white size=2>$sec</font></b> EOF
but all I am getting is the first element of the list $sec
being filled with this
Time::tm=ARRAY(0x15ab4e8)
with all the other elements being blank
I am obviously doing something wrong and would greatly
appreciate help
thanks

2005-10-16 Retitled by Arunbear, as per Monastery guidelines
Original title: 'gmtime'

Replies are listed 'Best First'.
Re: How to get the elements of gmtime() using Time::gmtime?
by Fang (Pilgrim) on Oct 16, 2005 at 09:06 UTC

    Have you read the documentation of Time::gmtime? It returns a blessed Time::tm object, which is stringified when you print it.

    To obtain what you want, use the methods provided by the object, as in:

    use Time::gmtime; my $tm = gmtime(); print $tm->sec; print $tm->min; # etc...

    Read perldoc Time::gmtime, all the info you need is in it.

Re: gmtime
by Zaxo (Archbishop) on Oct 16, 2005 at 12:40 UTC

    Time::gmtime() is a gussied-up version of the builtin gmtime. It returns a blessed hashref with the time struct elements given text labels as keys.

    Your usage is suitable for builtin gmtime, so you can fix it by leaving off the use Time::gmtime; line. One good reason to use the builtin is that its returned list is like localtime's, suitable arguments for POSIX::strftime. That is a very useful sprintf-like string formatter specialized for time functions.

    use POSIX 'strftime'; print strftime("Standard Time is %r.\n", gmtime);

    If all you want is the seconds' part, this will work:

    my ($sec) = gmtime; print <<"ETXT"; Content-Type: Text/html\n\n <b><font face="courier" color="white" size=2>$sec</font></b> ETXT

    After Compline,
    Zaxo