Update: See BillKSmith's (++) More algebra-savvy, and faster solution below.use strict; use warnings; my $n = shift or die "Need 'n' as param"; my $anon_sub = sub{ my $count=shift @_; my $sum_sqares=0; for my $i(1..$count){ $sum_sqares += $i**2; } return $sum_sqares; }; # CLose anon sub print "N=$n, sum squares=", $anon_sub->($n),"\n";
All power corrupts, but we need electricity.
In reply to Re: Anonymous Subroutine
by NetWallah
in thread Anonymous Subroutine
by mimiv89
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |