note
prasadbabu
<p>Hi [ferddle],<br><br>
You can use negative look ahead regex to accomplish your job. If you have whole file in a string $kml, then</p>
<c>use strict;
use warnings;
use Data::Dumper;
my $kml = do { local $/, <DATA>};
my %hash;
while ($kml =~ m/<name>((?:(?!<name>).)*)<\/name>\s*(<coordinates>(?:(?:(?!<coordinates>).)*)<\/coordinates>)/gs){
$hash{$1} = $2;
}
print Dumper \%hash;
output:
-------
$VAR1 = {
'One more' => '<coordinates>56,78,0</coordinates>',
'This is the title' => '<coordinates>12,34,0</coordinates>'
};
</c>
<p>You can learn more about positive look ahead at [doc://perlre].</p>
<p>updated, added code. Thanks to [ikegami] for pointing out the mistake.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-360010">
<p>Prasad</p>
</div></div>
688802
688802