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

#!/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]

Replies are listed 'Best First'.
Re^4: Private Variables and FastCGI / ModPerl
by expresspotato (Beadle) on Feb 11, 2010 at 04:30 UTC
    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.