First of all, many thanks for the helpful assistance and good advice from @choroba and @hippo!
I have taken up your input and build the following script:
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
my $infile = $ARGV[0];
my @regexes = (qr/§\s*[0-9]/, qr/Art\.\s*[0-9IVX]/, qr/Artikel\s*
+[0-9IVX]/, qr/Artikels\s*[0-9IVX]/, qr/Artikeln\s*[0-9IVX]/);
open my $in, '<', $infile or die "Cannot open $infile for reading: $!"
+;
my $xml;
{
local $/ = undef;
$xml = <$in>;
}
my $tally;
for my $i (0 .. $#regexes) {
my $regex = $regexes[$i];
++$tally[$i] while $xml =~ /$regex/g;
}
for my $i (0 .. $#regexes) {
print "$regexes[$i]:\t$tally[$i]\n";
}
close $in;
With use strict; I get the following error message:
Global symbol "@tally" requires explicit package name (did you forget
+to declare "my @tally"?) at monk2.pl line 24.
Global symbol "@tally" requires explicit package name (did you forget
+to declare "my @tally"?) at monk2.pl line 28.
Execution of monk2.pl aborted due to compilation errors (#1)
(F) You've said "use strict" or "use strict vars", which indicates
that all variables must either be lexically scoped (using "my" or
+"state"),
declared beforehand using "our", or explicitly qualified to say
which package the global variable is in (using "::").
Uncaught exception from user code:
Global symbol "@tally" requires explicit package name (did you
+ forget to declare "my @tally"?) at monk2.pl line 24.
Global symbol "@tally" requires explicit package name (did you
+ forget to declare "my @tally"?) at monk2.pl line 28.
Execution of monk2.pl aborted due to compilation errors.</i>
As the variable $tally is defined beforehand and preceded by the keyword "my", I don't understand what is wrong. How could I fix this?
If I run the same script without use strict;, the output looks like this:
(?^:§\s*[0-9]): 3
(?^:Art\.\s*[0-9IVX]): 2
(?^:Artikel\s*[0-9IVX]): 2
(?^:Artikels\s*[0-9IVX]): 2
(?^:Artikeln\s*[0-9IVX]): 2
How could I get rid of "(?^:" and ")"? Would it be possible to save this output to a file?
Have a nice afternoon!