Cool/useful short examples of Perl?

Dave Cross dave at dave.org.uk
Thu Jun 9 14:33:35 BST 2011


On 06/09/2011 01:39 PM, Imre Saling wrote:
> Quoting "Ruud H.G. van Tol" <rvtol at isolution.nl>:
>>
>> # see also perlvar: $BASETIME
>> { my $t0 = time; sub elapsed { time - $t0 } }
>
> or to get the elapsed time since the last call to elapsed():
>
> my $t0 = time;
> sub elapsed {
>   my $t = time;
>   my $dt = $t - $t0;
>   $t0 = $t;
>   return $dt;
> }

If we're talking about modern Perl, then that looks like a perfect use 
for a state variable.

Dave...


More information about the london.pm mailing list