First of all, many thanks for your valuable input and kind assistance!
I have managed to generate a statistics for the XML entities in a file in two steps:
entityList.pl
#!/usr/bin/perl use warnings; use strict; my $infile = $ARGV[0]; print "List of entities in ", $infile, "\n"; #define regexes as search target (in the array @regexes) my $regex = qr/(&[^;]+;)/; open my $in, '<', $infile or die "Cannot open $infile for reading: $!" +; #read input file in variable $xml my $xml; { local $/ = undef; $xml = <$in>; } #define output file open my $out, '>', 'ent-list.txt' or die $!; #output list of entities print {$out} "$1\n" while $xml =~ /$regex/g; close $in; close $out;
entityStat.pl
#!/usr/bin/env perl use strict; use warnings; my $infile = $ARGV[0]; my $outfile = $ARGV[1]; open(IN, '<' . $infile) or die "Cannot open $infile for reading: $!"; open(OUT, '>' . $outfile) or die $!; chomp(my @matches = <IN>); my %freq; $freq{$_}++ for @matches; print OUT "Statistics of entities in '", $infile, "'\n================ +=================================\n"; for my $entity (sort keys %freq) { printf OUT "%-20s %10s \n", $entity, $freq{$entity}; }
In reply to Re^2: Counting matches and removing duplicates
by LexPl
in thread Counting matches and removing duplicates
by LexPl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |