Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Current time as variable?

by einerwitzen (Sexton)
on Dec 17, 2003 at 11:50 UTC ( [id://315306]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Current time as variable?
in thread Current time as variable?

it seems that they all work when the codes you gave are in one part. I tried it as

&starttime; &stoptime; sub starttime{ my $start = time; sleep 5; } sub stoptime{ my $end = time; my $elapsed = $end - $start; print $elapsed; }
and it always prints out as 1071679507 seconds

Replies are listed 'Best First'.
Re: Current time as variable?
by b10m (Vicar) on Dec 17, 2003 at 12:08 UTC
    That is because in sub stoptime, your script doesn't know what $start is, since you only declared that in the starttime sub. Now if you'd do it like the following, it would print out 5:
    my $start; my $end; &starttime; &stoptime; sub starttime{ $start = time; sleep 5; } sub stoptime{ $end = time; print $end - $start."\n"; }

    Update: If you'd put "use strict;" in the beginning of your little snippet, Perl would warn you about this with: Global symbol "$start" requires explicit package name at test line 14.

    --
    b10m

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315306]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.