<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
use strict;
use warnings;
use XML::SAX::Expat;

sub Counter::new { bless { count =&gt; 0 }, shift }
sub Counter::start_element { shift-&gt;{count}++  }

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

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

printf "%s has %d elements\n", $ARGV[0], $counter-&gt;{count};
</pre></body></html>