줄 수, 단어 수, 문자 수를 인쇄하고 파일의 단어뿐만 아니라 발생하는 시간을 인쇄하려고합니다. 마지막 부분에 오류가 발생합니다 (즉, 단어를 출력하고 그 결과를 출력 함). 다른 모든 것은 잘 작동합니다.텍스트 파일에 단어 빈도 인쇄 Perl
오류 메시지는 내가 얻을 : 여기
Bareword found where operator expected at wc.pl line 34, near ""Number of lines: $lcnt\","Frequency"
(Missing operator before Frequency?)
syntax error at wc.pl line 34, near ""Number of lines: $lcnt\","Frequency of "
Can't find string terminator '"' anywhere before EOF at wc.pl line 34.
내 코드입니다 :
샘플 입력을 txt 파일에서 :
#!/usr/bin/perl -w
use warnings;
use strict;
my $lcnt = 0;
my $wcnt = 0;
my $ccnt = 0;
my %count;
my $word;
my $count;
open my $INFILE, '<', $ARGV[0] or die $!;
while(my $line = <$INFILE>) {
$lcnt++;
$ccnt += length($line);
my @words = split(/\s+/, $line);
$wcnt += scalar(@words);
foreach $count(@words) {
$count{@words}++;
}
}
foreach $word (sort keys %count) {
print "Number of characters: $ccnt\n","Number of words: $wcnt\n","Number of lines: $lcnt\","Frequency of words in the file: $word : $count{$word}";
}
close $INFILE;
이 내가 할 필요 무엇
This is a test, another test
#test# 234test test234
샘플 출력 :
Number of characters: 52
Number of words: 9
Number of lines: 2
Frequency of words in the file:
--------------------------------
#test#: 1
234test: 1
This: 1
a: 1
another: 1
is: 1
test: 1
test,: 1
test234: 1
어떤 도움을 크게 감상 할 수있다!
도움에 감사드립니다! @DavidO – chomp