XLII is the answer

ferreira on 2007-06-29T20:17:11

Acme::Roman was released to CPAN today (http://search.cpan.org/dist/Acme-Roman). With this module, it is a piece of cake to use Roman numerals in Perl.

For instance, you may try:

use Acme::Roman;

print I + II, "\n"; # III, as it should
print X * 2, "\n"; # XX
print X - 'III', "\n"; # VII

print "VI! = ", VI*V*IV*III*II*I, "\n"; # VI! = DCCXX

Among the distribution files, there are more examples in eg/roman.pl.

Only an implementation issue made me sad: a brute force method needed to force barewords into subs, resolved by an imported AUTOLOAD. It seems like Ruby got the upper hand over Perl this time. See the explanation at a node I wrote at PerlMonks: AUTOLOAD, overload, and Roman numerals for Perl.