I really hate to do this to you. I know I always got frustrated when I got this type of answer. But I personally learned much better when I had to do the specific research myself. Clipping code won't help you. Building it, fixing it and figuring out why your code doesn't work will help you.

So the first thing you want to do is learn about regexp (regular expressions). It's kind a wierd concept, but once you learn how to look at your source file, it grows easier and easier.

Now, your data is a variable. I'm assuming you'll eventually want to read this from a file? Correct? I have a recommendation. If you're going to read the data from a file, I highly recommend you set your script up to do that already. It may affect the behavior of your regexp in the long run. Best to get the environment into place and code around it rather than to force the environment to fit your code.

Anyhow, regexps work by finding and or find/replace methods. You'll search for the elements that you want. Actually, in this case, you'll be searching for the things that break up the elements you want. I could be wrong, but it looks to me that your list is separated by line breaks and space breaks. So you'll want to read all the data from your variable, and search through it looking for spaces and line breaks. You'll of course want to replace each with the appropriate html code. Don't forget to start each line with a new line and cell.

Since you're new to perl, I'd figure out how to replace these spaces and elements one at a time. You'll want to iterate through your big variable stream more than once. This is not common practice for later down the road, as it is a bit slow, but it'll help you to understand what is/isn't working if something breaks. Then figure out how to optimize it by combining all the search/replaces at once.

--Coplan


In reply to Re: Parsing Variables by Coplan
in thread Parsing Variables by JoeJaz

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.