Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Parsing huge XML file

by Gangabass (Vicar)
on Sep 04, 2011 at 00:40 UTC ( #924032=note: print w/replies, xml ) Need Help??

in reply to Re: Parsing huge XML file
in thread Parsing huge XML file

Thank you for pointing me right direction. I have rewritten it:

use strict; use warnings; use XML::Twig; my %bedrooms; my @bedrooms; my @good_division_numbers = qw( 30 31 32 35 38 ); my $xml = XML::Twig->new( twig_roots => { DivisionHouseRoom => \&count_bedroom +s, } ); $xml->parsefile( 'divisionhouserooms-v3.xml'); #$xml->parsefile('test.xml'); print "=" x 40, "\n"; open my $fh, ">>", "Result.csv" or die $!; foreach my $house_code (@bedrooms) { print $fh join( "\t", $house_code, $bedrooms{$house_code} ), "\n"; } close $fh; sleep 1; sub count_bedrooms { my ( $twig, $element ) = @_; my $house_code = $element->first_child_text('HouseCode'); print $house_code, "\n"; unless ( exists $bedrooms{$house_code} ) { push @bedrooms, $house_code; } my ($divisions) = $element->children('Divisions'); my @divisions = $divisions->children('Division'); for my $division (@divisions) { next unless grep { $_ eq $division->first_child_text('DivisionNum +ber') } @good_division_numbers; $bedrooms{$house_code} += $division->first_child_text('DivisionQuantity'); } $element->purge; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://924032]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-06-22 23:09 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.