in reply to xml::twig and node names

well my script is done now but it's really slow.
i made another one that just parses the xmlfiles as if they were just textfiles.
that took about 4 seconds for 5 files, but using twig it takes 116 seconds...

this is my code :
::twig
sub readxml{ $xmlfile = shift; my $twig= new XML::Twig(twig_handlers => { '/kvdt' => \&fall }); + $twig->parsefile($xmlfile); } sub fall{ my( $twig, $element)= @_; my @scheine = $element->get_xpath('.//*'); foreach my $schein (@scheine){ my $fk = $schein->name; if ($schein->{att}->{USE}){($schein->{att}->{USE} =~ /EDV/)?(n +ext):();} if ($fk =~ /fk....\b/){ my $key = substr($fk,2,4); $data{xml}{$key}++; } } }
text
sub readxml{ $xmlfile = shift; open(XML, $xmlfile); while(<XML>){ chomp(); my $line = $_; my @bla; ($line =~ /USE="EDV"/)?(next):(); if ($line =~ /<fk....[^_]/){ @bla = split(/<fk/,$line); my $key = substr($bla[1],0,4); #30 $data{xml}{$key}++; } } close(XML); }
is there a way to make this faster using ::twig ?

Replies are listed 'Best First'.
Re^2: xml::twig and node names
by m0ve (Scribe) on Sep 21, 2007 at 08:33 UTC
    i was able to improve it by using this :
    sub readxml{ $xmlfile = shift; my $twig= new XML::Twig( twig_handlers => { '_all_' => \&fall }, ); $twig->parsefile($xmlfile); } sub fall{ my( $twig, $element)= @_; if (!$element->{att}->{USE} || $element->{att}->{USE} !~ /EDV/){ if ($element->name =~ /fk....\b/){ my $key = substr($element->name,2,4); $data{xml}{$key}++; } } }
    but it still takes ~80 seconds...