in reply to RegEx Riddle
What I read is that you want to associate the very next occurrence of coordinates, and the next occurrence only, with the last occurring name. Then:
$coords_found_flag = 0; open(KMLFILE, $kml_file) or die("cannot open file : $kml_file $! "); while ($line = <KMLFILE>) { if ($line =~ m/<name>(.*)<\/name>/) { $current_name = $1; $coords_found_flag = 0; } elsif ($line =~ m/<coordinates>(.*)<\/coordinates>/ && $coords_fou +nd_flag == 0) { $coords{$current_name} = $1; $coords_found_flag = 1; } } close(KMLFILE);
|
|---|