I've just taken a look at the VSK5 markup. Converting this to HTML is a rather complicated algorithm to implement for a new Perl programmer. Even assuming your algorithm skills from C programming come back to you, you will also need to learn a great deal of Perl syntax and conventions to do this. If this is a learning project, you might want to try something a little less ambitious.
To implement this you are going to need to:
- create a mapping between the codes and HTML. The mapping will require either in-line CSS or style sheets as some of the attributes are not supported in CSS. You can partly implement this in a lookup table. However, I think you will find constructing a look up table for all of the color markup quite tedious and unmanagable. You will need a function to convert $[0-9a-f][0-9a-f][0-9a-f] the three digit RGB to the 6 digit RGB used by HTML. The function will also need to generate the appropriate style attribute for that HTML
- In well formed HTML, each open tag should match a close tag. Therefore in your generated HTML you are going to need to keep track of all of the open tags you insert. Then when you hit a $z you will need to close them in the reverse order in which you inserted them. This is best managed using an array to hold the tags, push to store the open tags and pop to get the close tags for insertion.
- You may want to consider implementing $t as you read in characters. See uc for a routine to convert letters to upper case.
- You could try to use a fancy regex to parse the string and find all of the VSK5 markup. If you want to do that, check out perlre and perlretut. However, I think you might find it easier to convert the markup by writing a simple state engine that loops through all of the characters of the string and sets the state (processing character or attribute) based on what character is following any $ you encounter. To break the string into characters, use split(//,$sAttributedShipName). split uses the special regular expression // to split a string into characters.
- You may also want to consider a two phase conversion process. In pass one, you convert the string into an array of array references or hash references. Each array reference (or hash reference) would store the letter at position N and all of the attributes that will be set just before that letter. In the second pass, you would convert the array to HTML text. The two phase approach will help you avoid empty HTML tags that arise if someone has an attribute sequence like $i$z. If you choose this approach, you may find perlref helpful.
I did write up a short demo program to generate the HTML (partly to understand what you need to learn to do this task). However, since this is a learning site and not a code writing service, I'd like to see your first attempt at this problem before I post any code.
Best of luck, beth
P.S. There is apparently a book especially designed for C programmers trying to learn Perl - I haven't read it but you might want to take a look at it: Perl for C Programmers.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.