Cool/useful short examples of Perl?

Gabor Szabo szabgab at gmail.com
Thu Jun 9 14:26:10 BST 2011


On Thu, Jun 9, 2011 at 3:39 PM, Imre Saling <imre.saling at saling.ch> wrote:
> Quoting "Ruud H.G. van Tol" <rvtol at isolution.nl>:
>>
>>    # see also perlvar: $BASETIME
>>    { my $t0 = time; sub elapsed { time - $t0 } }
>>
>> --
>> Ruud
>
>
> 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;
>  }
>


my bikeshed has nicer color:


use 5.010;
use Time::HiRes qw(time);

say elapsed();
say elapsed();

sub elapsed {
   state $t0 = $^T;

   my $t = time;
   my $dt = $t-$t0;
   $t0 = $t;
   return $dt;
}


Gabor



More information about the london.pm mailing list