Created
March 22, 2012 10:23
-
-
Save draegtun/2157592 to your computer and use it in GitHub Desktop.
Saw this and just wanted to play!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# see http://perl.plover.com/idiocy/Addition.pm by MJD | |
# | |
use 5.014; | |
use warnings; | |
{ | |
package Compute; | |
use Carp; | |
sub AUTOLOAD { | |
(my $name = our $AUTOLOAD) =~ s/^.*:://; | |
if ($name =~ m/^startWith(\d+)/) { | |
my $sum = $1; | |
while ($name =~ m/(\D+)(\d+)/g) { | |
given ($1) { | |
$sum += $2 when [qw/add plus/]; | |
$sum -= $2 when [qw/minus subtract/]; | |
} | |
} | |
no strict 'refs'; | |
*$AUTOLOAD = sub { $sum }; | |
goto &$AUTOLOAD; | |
} | |
croak "No compute!"; | |
} | |
} | |
say Compute->startWith10add2minus4; | |
say Compute->startWith12minus4minus1plus2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment