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


in reply to parse XML huge file using cpan modules

For really large files, you can use XML::LibXML::Reader.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML::Reader; my $r = 'XML::LibXML::Reader'->new(location => shift); say 'time|resourceGroup|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPPO +RT'; my %dispatch = ( statRecord => sub { print $r->getAttribute('time'), '|'; }, resourceGroup => sub { print $r->getAttribute('name'); }, name => sub { my $name = $r->readInnerXml; return unless $name =~ /^(?:LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPPORT)$ +/; $r->nextSiblingElement('value'); print '|', $r->readInnerXml; print "\n" if $name eq 'SIPPORT'; } ); while ($r->read) { next unless $r->nodeType == 1; my $action = $dispatch{ $r->name }; $action->() if $action; }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]