in reply to Re: Private Variables and FastCGI / ModPerl
in thread Private Variables and FastCGI / ModPerl

Thank you for your prompt response. Alright perhaps you can help me with this then... How can I keep variables results within a subroutine as if they were global? The following sub is used to see how long portions of code take to execute. But how can I keep $last_elapsed within the sub?
use Time::HiRes qw(tv_interval); &t('Reference Time'); sleep(2); &t('Did something'); sub t(){ my $t0 = [gettimeofday]; my $elapsed = tv_interval ( $t0 ); my $elapsed_o = $elapsed; $elapsed = $elapsed - $last_elapsed; if ($last_elapsed){printf ("(%s)%f<br>\n",$_[0],$elapsed);} $last_elapsed = $elapsed_o; }
Hope to hear from you, _Kevin

Replies are listed 'Best First'.
Re^3: Private Variables and FastCGI / ModPerl
by Anonymous Monk on Feb 11, 2010 at 04:10 UTC
    #!/usr/bin/perl -- use strict; use warnings; use Time::Elapse; Main(@ARGV); exit(0); sub Main { Time::Elapse->lapse( my $now = 'Reference Time' ); print "$now\n"; sleep 2; print "$now\n"; sleep 1; $now = 'Did something'; print "$now\n"; } ## end sub Main __END__ 16:00:00.000064 [Reference Time] 16:00:02.000000 [Reference Time] 16:00:00.000069 [Did something]
      Although that does fix the problems with that specific subroutine, it doesn't tell my how to keep a value live within a subroutine without wiping it each time the subroutine is called... local does fix the problem, using local $elapsed_time, within the FCGI loop and outside the subroutine.