Thomas Jakub wrote in message
<[EMAIL PROTECTED]>...
>How can I tell how much time a program has been
>running for in a perl script? I tried to do $time01 =
>localtime() and $time02 = localtime() and then
>subtract $time01 from $time02, but I always get zero,
>even though there was about five or so minutes of
>activity in between the parts where $time01 was
>defined and $time02 was defined. My guess is that it
>is not copying the variable over, but the memory
>location, and since the variable within that memory
>location is changing, both are changing, but this is
>all just a guess...
In a scalar context (assigned to an ordinary variable) the
localtime function returns the current time as a human
readable string. If you try to use this in a numeric context
then Perl will convert it to a value of 0, hence your result.
>So, does anyone know how I can tell how much time a
>program has elapsed in perl?
Perl has a built in variable which is the time in epoch seconds
that the program started (epoch seconds are the number of
seconds since a defined point in time, Jan 1 1970 00:00:00 on
UNIX). Perl also has a built in function called 'time' to return the
current time in epoch seconds.
So the answer is:
$running_time_in_secs = time-$^T;
Dave.