I have two arrays of text and XML tags and I'm trying to figure out which match up. Many of the tags are nested in other tags and may or may not exist at all in the other array For example
@array1 = ("Here ","<Tag Id=1>","is","</Tag>"," an ","<Tag Id=2>", "example that ","<Tag Id=3>","I","</Tag>"," just made","</Tag>") @array2 = ("<Tag Id=7>","Here is","</Tag>"," an ","<Tag Id=8>", "example that I just made","</Tag>")
Or shown joined up for easier reading
Array 1 = Here <Tag Id=1>is</Tag> an <Tag 2>example that <Tag Id=3> I</Tag> just made</Tag> Array 2 = <Tag Id=7>Here is</Tag> an <Tag 2>example that I just made</Tag>
As you can see (or perhaps not, my example isn't great) tag2 in @array1 matches tag 8 in @array2 while the other tags simply don't match up. The way that I've been attempting to solve this at the minute is simply by tracking how much of the actual text I've been through and using a heap of if statments to determine what to do. But it is quite long, and very hard to read. I'm thinking there must must be an easier way to do this, perhaps by filtering the array in some manner so that the tags that match can be easily mapped together. Or perhaps there is no easy solution. How would all you clever perl people go about solving a problem like this?

In reply to Matching up XML tags in 2 arrays by bwgoudey

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.