http://www.perlmonks.org?node_id=590364

madbombX has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I have been at this for much longer than should be necessary. I am using XML::Simple, but I have also unsuccessfully tried XML::Twig. The file (with an example below) I have a file that looks like what is below. Each tag is only used once. I know it is possible to use a few regexen, but the way I need to use the data later, having the data in a hash similar to one returned by XML::Simple.

<CVS> $Id: File_Find.pl,v 1.1 2006-12-17 19:25:03 eric Exp $ This That <this@that.com> Desc: Test file </CVS> <DATE>2006-12-10</DATE> <INTRODUCTION>Blah, <b>blah</b>, blah</INTRODUCTION> <TITLE>Foo</TITLE> <AUTHOR>Bar</AUTHOR> ... <ARTICLE> <p>foo, test</p> <p>bar</p> <p>baz</p> </ARTICLE>

When I have the above text, all I get is what's inside of <CVS>. When I add <XML> tags surrounding the whole file, all I get is the following using Data::Dumper:

$VAR1 = \{ 'CVS' => '<The entire file and this is the only tag in the + hash with no other tags even making it in here>'};

What is the best method to extract the data out of this file (either using an XML module or not) and pulling out what I need into a hash? Thanks.

Update: I forgot to include the code I actually tried. I know the $file is correct and @articles is populated.

foreach my $file (@articles) { my $article = XMLin($file, NoAttr => 1); use Data::Dumper; print "<pre>", Dumper(\$article), "</pre>"; }

Update 2: I think I need to provide a better example of the data. So look above at the data example and that gives a much better perception of what I am dealing with.