에서 당신은 한 줄이 작업을 수행하지 않으려면 :
#!/usr/bin/perl
use warnings;
use strict;
my $input = "
A 4481676 4483063
A 4481676 4483063
A 4481676 4483063
A 4481676 4483063
A 4483214 4483749
A 4483214 4483749
A 4483214 4483749
A 4483214 4483749
A 4483214 4483749
A 4483214 4483749";
my %seen;
while($input =~ /(.+)$/mg){
$seen{$1}++;
}
foreach my $key (keys %seen) {
print "$key $seen{$key}\n";
}
이것을 나타내는
Live demonstration은 원하는 outp ut. 당신의 입력 파일 인 경우, 단지 while($input =~ /(.+)$/mg)
의 장소에서의 FileHandler와 while(<>)
를 사용
#!/usr/bin/perl
use warnings;
use strict;
my $file="file.txt";
open(DATA, "<" . $file);
my %seen;
while(<DATA>){
$seen{$1}++;
}
foreach my $key (keys %seen) {
print "$key $seen{$key}\n";
}
도 일종의 data.txt로'... 스크립팅을 할 필요가 없습니다 | uniq -c'는 줄의 시작 부분에 셀 수를 두지 않는다면 작동합니다. – AKHolland
@Maryam'.pl' 파일에서 사용할 수 있고'Data :: Dumper' 모듈을 사용하지 않는 perl 응답을 제공했습니다. –