bwgoudey has asked for the wisdom of the Perl Monks concerning the following question:
Or shown joined up for easier reading@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>")
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?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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching up XML tags in 2 arrays
by ikegami (Patriarch) on Jan 15, 2007 at 06:21 UTC | |
by bwgoudey (Sexton) on Jan 16, 2007 at 02:02 UTC | |
by bobf (Monsignor) on Jan 16, 2007 at 03:16 UTC |