<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><DIV>MyfWhite wrote:</DIV>
<DIV>> I need to convert roman numerals to arabic, and there seem to be</DIV>
<DIV>> quite a few modules on the CPAN which can do this.<BR></DIV>
<DIV>Just in case you prefer a one liner to a CPAN module:</DIV>
<DIV> </DIV>
<DIV>use List::Util 'reduce';<BR>sub roman_to_dec {<BR> reduce{$a+$b-$a%$b*2}map{10**(7&69303333/ord)%9995}split//,uc(shift)<BR>}</DIV>
<DIV> </DIV>
<DIV>Only works for "modern" Roman Numerals in 1-3999 range ... and I</DIV>
<DIV>admit maintainability and readability may suffer. :)</DIV>
<DIV> </DIV>
<DIV>A while back, I wrote up a node describing the algorithm behind this</DIV>
<DIV>monstrosity and even gave it a name, the PGA-TRAM algorithm:</DIV>
<DIV> </DIV>
<DIV> <A href="http://www.perlmonks.org/?node_id=771219">http://www.perlmonks.org/?node_id=771219</A></DIV>
<DIV> </DIV>
<DIV>Cheers,<BR>/-\<BR></DIV><!-- cg17.c2.mail.re1.yahoo.com compressed/chunked Fri Dec 4 16:41:45 PST 2009 --></div><br>
<hr size=1>
See what's on at the movies in your area. <a href="http://au.rd.yahoo.com/movies/mailtagline/*http://au.movies.yahoo.com/session-times/" target=_blank>Find out now</a>.</body></html>