[sf-perl] alarmingly obscure perl on wikipedia
Matthew Lanier
matt at lanier.org
Sun Nov 20 10:40:41 PST 2011
kevin-
good idea. perl definitely suffers from a proliferation of bad code out
there.
m@
On Sun, 20 Nov 2011, Kevin Goess wrote:
> On the topic of trying to promote readable, modern Perl, I just happened to come across this in the wikipedia article on "Function Objects": http://en.wikipedia.org/wiki/Function_object#In_Perl. It's a terrible, terrible ambassador
> for Perl, and I think actually misses the point of the article. If you compare the Perl code with even the Javascript code it's downright embarrassing.
> I'm going to mirror the Javascript example and rewriting the Perl code as follows, anybody have any comments on this?
>
> In Perl, functions are first class objects. Perl also supports closures.
>
> sub make_accumulator {
> my $current = shift;
> return sub { return $current += shift };
> }
>
> $acc1 = make_accumulator(42);
> $acc2 = make_accumulator(9000);
>
> print $acc1->(3), "\n"; # prints '45'
> print $acc1->(3), "\n"; # prints '48'
> print $acc2->(542), "\n"; # prints '9542'
>
>
>
More information about the SanFrancisco-pm
mailing list