in reply to Re^4: Entity statistics
in thread Entity statistics

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?

You have declared $tally which is a scalar but the errors are telling you about @tally which is an array. Since your loops refer to the array and not the scalar, that is what you need to declare instead. See the basic datatypes, three for more about the basic data types in Perl and how the sigils relate to them.

How could I get rid of "(?^:" and ")"?

You could process the string which you actually output to achieve this but in this particular case you can avoid that by using quotes to delimit each regex in the first place instead of using the qr// operator. You can use single quotes 'foo' or q/foo/ for non-interpolated strings. ie:

my @regexes = (q/§\s*[0-9]/, q/Art\.\s*[0-9IVX]/, q/Artikel\s*[0- +9IVX]/, q/Artikels\s*[0-9IVX]/, q/Artikeln\s*[0-9IVX]/);

Bear in mind that these are now just simple strings so you need to take care to explicitly use them in a regex content. But as that is what the rest of your code does anyway, there is no further change required here.

Would it be possible to save this output to a file?

Of course. See eg. Re: How do I write to a file?

Do have a browse through the Tutorials section here and the Getting Started with Perl section in particular. These should help you achieve some of these simple tasks while you become more familiar with the language.


🦛