For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > December 2007 > Timestamp sub









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Timestamp sub
Henrik Nielsen

2007-12-12, 7:02 pm

Hi

Whats with the \$t in this sub?
sub timestamp { my $t = localtime; \$t }

And what does this do?
sub timestamp { my $t = localtime; }

Henrik
Yitzle

2007-12-12, 7:02 pm

In perl, the last variable ____ in a function is returned.
sub timestamp { my $t = localtime; \$t }
is the same as
sub timestamp { my $t = localtime; return \$t; }
This function stores the localtime (seconds since epoch?) in a
variable $t, then returns a reference to $t.
Tom Phoenix

2007-12-12, 7:02 pm

On 12/12/07, Henrik Nielsen <quercus1974@gmail.com> wrote:

> Whats with the \$t in this sub?
> sub timestamp { my $t = localtime; \$t }
>
> And what does this do?
> sub timestamp { my $t = localtime; }


The localtime function is documented in the perlfunc manpage. It's
being used here in a scalar context. References are covered in the
perlreftut manpage, among others. Is that what you're looking for?

Cheers!

--Tom Phoenix
Stonehenge Perl Training
Gunnar Hjalmarsson

2007-12-12, 7:02 pm

yitzle wrote:
>
> sub timestamp { my $t = localtime; return \$t; }
> This function stores the localtime (seconds since epoch?) in a
> variable $t


No, seconds since epoch is not what localtime() returns and what's
stored in $t.

perldoc -f localtime

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com