Mr.Churka has asked for the wisdom of the Perl Monks concerning the following question:
I don't think that the program is calling the handlers properly when the file is parsed. The strangest part is that it keeps returning a value of 1. Did I somehow put the populate sub into a Boolean context? What am I doing wrong? Is there an easier way to get what I'm after? Thanks!use XML::Twig; my $twig=XML::Twig->new( twig_handlers => { title => sub { $_->set_gi( 'h2') }, # tags to h2 para => sub { $_->set_gi( 'p') }, # para to p populate=> sub { while (<>) { if (%Items !~ m/"<us:"|"<oa:"(.*)/) { $Items{$1} =1} else {$Items{$2} =($Items{$1}+(/$1/)) } #If element is not in the hash, adds it #If element is in the hash, adds the number of matches to the value }; }, hidden => sub { $_->delete; }, # remove hidden elements list => \&my_list_process, # process list elements div => sub { $_[0]->purge; }, # free memory }, ); $twig->parsefile( 'bigXMLfile.xml'); # build it print %Items; # output the twig $twig->purge; # clear end of document from memory
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using XML Twig to summarize a large file
by GrandFather (Saint) on Nov 06, 2007 at 22:16 UTC | |
|
Re: Using XML Twig to summarize a large file
by Skeeve (Parson) on Nov 06, 2007 at 21:54 UTC | |
by Anonymous Monk on Nov 07, 2007 at 14:58 UTC | |
by mirod (Canon) on Nov 07, 2007 at 16:10 UTC | |
by Mr.Churka (Sexton) on Nov 07, 2007 at 17:03 UTC | |
by mirod (Canon) on Nov 07, 2007 at 17:40 UTC | |
|
Re: Using XML Twig to summarize a large file
by mirod (Canon) on Nov 07, 2007 at 08:16 UTC | |
|
Re: Using XML Twig to summarize a large file
by weismat (Friar) on Nov 06, 2007 at 18:42 UTC |