Anonymous user
Averages/Simple moving average: Difference between revisions
→{{header|Perl}}: some more clarification and code clean-up
(→{{header|Perl}}: clean up code (this is not a golf contest!), fix small bug, and add usage demonstration) |
(→{{header|Perl}}: some more clarification and code clean-up) |
||
Line 2,235:
=={{header|Perl}}==
Using an initializer function which returns an anonymous closure which closes over an instance ''(separate for each call to the initializer!)'' of the lexical variables <code>$period</code>, <code>@list</code>, and <code>$sum</code>:
<lang perl>sub sma_generator {
my $period = shift;
my (@
return sub {
return $sum / @list;
}
}
|