- 论坛徽章:
- 0
|
回复 3# Windows19
稍作改变:
- #!/usr/bin/perl
- use strict;
- use warnings;
- my %seen;
- open DATA, "<", shift;
- while ( my $word = <DATA> ) {
- chomp $word;
- for my $char ( split("", $word) ) {
- next if $char !~ /[a-zA-Z]/;
- #next if $char !~ /[0-9]/;
- $seen{$char}->{num}++;
- push @{$seen{$char}->{word}}, $word;
- }
- }
- my %print_seen;
- for my $char ( sort {$seen{$b}->{num} <=> $seen{$a}->{num}} keys %seen ) {
- for my $word ( @{$seen{$char}->{word}}) {
- next if $print_seen{$word}++;
- print $word, "\n";
- }
- }
- close DATA;
复制代码
|
|