具有哈希的Perl语法错误

Pre*_*ick 1 syntax perl

我是Perl的新手,当我尝试使用哈希时,编译器给我一个语法错误.这就是问题所在:

while (<>){
    @words_in_line = /[a-z](?:[a-z']*[a-z])?/ig;
    foreach $word (@words_in_line){
            %wordcount{$word}++;
    }
}
Run Code Online (Sandbox Code Playgroud)

而我得到的错误是

syntax error at ./wordfreq.pl line 11, near "%wordcount{"
syntax error at ./wordfreq.pl line 11, near "++;"
syntax error at ./wordfreq.pl line 13, near "}"
Execution of ./wordfreq.pl aborted due to compilation errors. 
Run Code Online (Sandbox Code Playgroud)

too*_*lic 7

要访问哈希值,请使用标量符号$.更改:

        %wordcount{$word}++;
Run Code Online (Sandbox Code Playgroud)

至:

        $wordcount{$word}++;
Run Code Online (Sandbox Code Playgroud)

perldoc perldata