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

When I try to implement the following code:

while (my @row = $sth->fetchrow_array()){ my $parser = XML::LibXML->new(); my $doc = $parser->parse($row[0]); my $root = $doc->documentElement(); my %linked_counts_by_abbr; for my $usage_node ($root->findnodes('/Boo +kReferences/BookUsage')) { my $abbr = $usage_node->getAtt +ribute('BookAbbr'); my $linked_count = $usage_node->getAtt +ribute('LinkedCount'); $linked_counts_by_abbr{$abbr} += $link +ed_count; } foreach (my ($key, $value) = each %linked_ +counts_by_abbr){ print OUTPUT "$key => $value\n"; } }
(which I got mostly from this site!) I get the following error.

Can't locate auto/XML/LibXML/parse.al in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 .) at registrations_by_discipline_with_contacts.pl line 139

Any suggestions? libxml-parser-perl package v2.34 is installed along with the necessary dependencies and I'm on Debian GNU/Linux 4.0 but don't have SUDO privilages and I log in to the sytem remotely via a VPN connection.

Replies are listed 'Best First'.
Re: Trouble using XML::LibXML
by AnomalousMonk (Archbishop) on Oct 08, 2009 at 06:51 UTC
    BTW:
    foreach (my ($key, $value) = each %linked_counts_by_abbr){ print OUTPUT "$key => $value\n"; }
    I would be surprised if this loop does what you think and hope it does. Iteration over a hash with each is usually implemented with a  while loop (see perlsyn for  while loop info).
    >perl -wMstrict -le "my %hash = qw(a 1 b 2 c 3 d 4); print 'foreach loop output:'; foreach (my ($k, $v) = each %hash) { print qq{$k => $v}; } print 'while loop output:'; keys %hash; while (my ($k, $v) = each %hash) { print qq{$k => $v}; } " foreach loop output: c => 3 c => 3 while loop output: c => 3 a => 1 b => 2 d => 4
    (PS: Does anyone know why the OP is rendering so strangely?)
Re: Trouble using XML::LibXML
by afoken (Chancellor) on Oct 08, 2009 at 06:08 UTC

    It seems that XML::LibXML has no parse() method. A quick look at the documentation on CPAN shows several specialised parsing methods instead, like parse_fh(), parse_file(), parse_string(). Are you sure you did not want to call parse_string()?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Trouble using XML::LibXML
by derby (Abbot) on Oct 08, 2009 at 12:47 UTC

    Other's have identified the core problem but ... you might also benefit by moving the instantiation of your parser outside of the loop:

    my $parser = XML::LibXML->new(); while (my @row = $sth->fetchrow_array()){ my $doc = $parser->parse($row[0]); ... }

    -derby
Re: Trouble using XML::LibXML
by kdmurphy001 (Sexton) on Oct 08, 2009 at 09:14 UTC
    Woot, that worked perfectly. Thanks yet again!