Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found