Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 10eed9c316d684c239729d6a252c5851 > files > 11

perl-XML-SAX-Expat-0.500.0-2.mga4.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};