내 질문에 Perl이 : Perl 스크립트 텍스트 (문장 부호 또는 숫자 없음)를 읽고 정렬 된 단어 목록과 텍스트에 각각 번을 인쇄하는 스크립트.왜 Perl로 단어를 정렬하는 것이 잘못 되었습니까?
#!/usr/bin/perl
@names = qw(My name is Ashok Rao and I am the son of Shreesha Rao and Shailaja Rao);
join(',',@names);
my %count;
foreach (@names)
{
if (exists $count{$_})
{
$count{$_}++;
}
else
{
$count{$_} = 1;
}
}
my @order = sort(@names);
print "The words after sorting are:\n";
print "@order\n";
print "The number of times each word occurring in the text is: \n";
foreach (keys %count)
{
print "$_ \t = $count{$_}\n";
}
출력은 다음과 같습니다 : 내 스크립트입니다
The words after sorting are:
Ashok I My Rao Rao Rao Shailaja Shreesha am and and is name of son the
The number of times each word occurring in the text is:
the = 1
son = 1
of = 1
name = 1
Ashok = 1
Shailaja = 1
is = 1
Rao = 3
am = 1
My = 1
I = 1
and = 2
Shreesha = 1
하지만 정렬 부분 출력이 잘못 생각합니다. 단어 발생 부분 출력이 정확합니다. 도와주세요. 미리 감사드립니다.
어떻게 잘못 되었나요? perl은 대문자와 소문자를 구별합니다. –
오. 네 말이 맞아. 나는 그것을 알아 차리지 못했다. 감사합니다 – user1613245
'ASCII 코드'에 따르면 정렬 순서가 정확합니다. 어떻게 그들을 분류하기를 원합니까? –