- or download this
#!/usr/bin/perl -w
use strict;
...
print_add 2,2;
print_add 2,2,2;
print_add 4,8,12;
- or download this
root@swill ~/PerlMonks
$ ./adder_1.pl
2 + 2 = 4
2 + 2 + 2 = 6
4 + 8 + 12 = 24
- or download this
sub add {
my $accumulator = 0;
...
}
$accumulator;
}
- or download this
#!/usr/bin/perl -w
use strict;
...
'Recursive' => sub { 2 == add_rec(2,2); },
'Iterative' => sub { 2 == add_iter(2,2); }
});
- or download this
$ ./adder_bench.pl
Rate Recursive Iterative
Recursive 79051/s -- -48%
Iterative 152207/s 93% --