I believe that this code does what you want.

First it creates a string of 7 dots, then it will look for each letter, if it finds it, it sets all charachters after it (in the output string) to dots, and removes all occurence of that charachter from the input string.

my %Lookup = (M => 0, D => 1, C => 2, L => 3, X => 4, V => 5, I => 6); while (<DATA>) { my $out = "." x 7; while (m/([MDCLXVI])/g) { substr ($out, $Lookup{$1}) = "." x (length($out) - $Lookup{$1}); substr ($out, $Lookup{$1}, 1, $1); s/$1//g; } print $out; }

Note, this code is similar to tlm's code, except that his code does not reset the dots, which is what the OP wants... (or atleast I guess that's what he wants by looking at the desired output)

Update: typo + note about tlm's code

Update2: code has a bug... input: 'XL', 'XC' and 'CDXLVI' do not generate the correct output...

Update3: I fail to see the consintency in the OP's desired output.

XL, and XC should result in X, which would mean that any charachter following X (other then V and I) should be ignored, but CDXLVI should result in .D..XVI, meaning that the C is ignored... this makes no sense to me.


In reply to Re: Help with a Regex by Animator
in thread Help with a Regex by planetscape

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.