Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > ff8f5941ce8b4cb5c9330b4498c9906b > files > 8

perl-XML-SAX-Expat-0.510.0-7.mga7.noarch.rpm

#!/usr/bin/perl -w
use strict;
use warnings;
use XML::SAX::Expat;

sub Counter::new { bless { count => 0 }, shift }
sub Counter::start_element { shift->{count}++  }

if (@ARGV != 1) {
  print "Usage: $0 example.xml\n";
  exit;
}

my $counter = Counter->new;
my $parser = XML::SAX::Expat->new(Handler => $counter);
$parser->parse_file($ARGV[0]);

printf "%s has %d elements\n", $ARGV[0], $counter->{count};