Monks,
I have a KML file that I need to parse. I would like to do this without the help of a module. Here is an example:I would like to create hashes from all occurrences of <name> and its corresponding <coordinates>.<Placemark> <name>This is the title</name> ... <coordinates>12,34,0</coordinates> </Placemark> <Placemark> <name>This is another title</name> </Placemark> <Placemark> <name>One more</name> <coordinates>56,78,0</coordinates> ... <coordinates>-99,-88,0</coordinates> </Placemark>
Great, all I need is a way to find any <coordinates> tags that occur on lines after <name>, so that each coordinate is stored in a hash with its corresponding name. One of the problems with this is that there are some <name> tags that exist without <coordinates> (center three lines in the example above).foreach (@kmlFile) { if (m/<name>(.*)<\/name>/) { %{$1} = (name => "<name>$1</name"); } }
In other words, the code need only extract the next <coordinates> that occur after a <name> -- these coordinates would only be associated with the <name> that preceeds it, all other <coordinates> would be ignored until found again after the next <name>.
These occurrences are not necessarily on consecutive lines
From the above, I would need:%This is the title = ( name => "<name>This is the title</name", coordinates => "<coordinates>12,34,0</coordinates>", ) %One more = ( name => "<name>One more</name>", coordinates => "<coordinates>56,78,0</coordinates>", )
If a mod is the only option, please let me know...
Thanks for any help,-Newbs
In reply to RegEx Riddle by ferddle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |