in reply to Printing a Tag content
Use XML::Twig or XML::TreeBuilder. Life is not long enough to roll your own XML/HTML/CSV parser. To get you started:
use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new(); $twig->parse (do {local $/; <DATA>}); my @chunks = $twig->root ()->children(); my %lookup; for my $chunk (@chunks) { my $words = $chunk->first_child ('words'); my $text = $words->xml_text (); push @{$lookup{$_}}, $chunk for split /,\s+/, $text; } #do stuff with %lookup __DATA__ <doc> <MS_1> <loc>c:\data\cat.xml</loc> <words>dog, cat, fish, bird</words> </MS_1> <MS_2> <loc>c:\data\cow.xml</loc> <words>dog, cat, fish, bird, cow, goat</words> </MS_2> <MS_3> <loc>c:\data\snake.xml</loc> <words>dog, cat, fish, bird, snake, orange</words> </MS_3> </doc>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Printing a Tag content
by codeacrobat (Chaplain) on Apr 03, 2006 at 20:49 UTC |