[Melbourne-pm] Roman numerals & assessing a CPAN module

Andrew Savige ajsavige at yahoo.com.au
Fri Dec 11 20:12:43 PST 2009


MyfWhite wrote:
> I need to convert roman numerals to arabic, and there seem to be
> quite a few modules on the CPAN which can do this.

Just in case you prefer a one liner to a CPAN module:

use List::Util 'reduce';
sub roman_to_dec {
 reduce{$a+$b-$a%$b*2}map{10**(7&69303333/ord)%9995}split//,uc(shift)
}

Only works for "modern" Roman Numerals in 1-3999 range ... and I
admit maintainability and readability may suffer. :)

A while back, I wrote up a node describing the algorithm behind this
monstrosity and even gave it a name, the PGA-TRAM algorithm:

 http://www.perlmonks.org/?node_id=771219

Cheers,
/-\



      __________________________________________________________________________________
See what's on at the movies in your area. Find out now: http://au.movies.yahoo.com/session-times/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20091211/c30a94ea/attachment.html>


More information about the Melbourne-pm mailing list