我一直在学习Perl,每当我写一个非平凡的脚本时,我总会得到这个错误信息.我一直认为我对它有很好的理解,但我想我没有.这是一个草率马尔可夫链示例(未测试),下面的错误.
该
#!/usr/bin/perl -w use strict; sub croak { die "$0: @_: $!\n"; } sub output { my %chains = shift; my @keys = keys %chains; my $index = rand($keys); my $key = $keys[$index]; my $out_buf = $key; for (my $i = 0; $i < 100; ++$i) { my $aref = $chains{$key}; my $word = @$aref[rand($aref)]; $out_buf .= " $word"; $key =~ s/.+ //; $key .= " $word"; } print $out_buf,"\n"; } sub get_chains { my %chains; my @prefixes while (my $line = <FILE>) { my @words = split " ",$line; foreach my $word (@words) { if ($prefixes == 2) { my $key = join " ",@prefixes; my $arr_ref = $chains{$key}; push(@$arr_ref,$word); shift @prefixes; } push(@prefixes,$word); } } return %chains; } sub load_book { my $path_name = shift @ARGV; open(FILE,$path_name) || croak "File not found.\n"; } load_book; my %chains = get_chains; output %chains; ----ERRORS---- "my" variable $line masks earlier declaration in same statement at markov.pl line 33. "my" variable $path_name masks earlier declaration in same scope at markov.pl line 55. Global symbol "$keys" requires explicit package name at markov.pl line 12. Syntax error at markov.pl line 32,near ") {" Global symbol "$prefixes" requires explicit package name at markov.pl line 36. Global symbol "%chains" requires explicit package name at markov.pl line 48. Syntax error at markov.pl line 49,near "}" Syntax error at markov.pl line 56,near "}" Execution of markov.pl aborted due to compilation errors.
我犯了什么错误?