Perl リストソート
メモ
- 昇順と降順を逆にしたい場合は {$a cmp $b} の $a と $b を逆にし {$b cmp $a} とする。
ソース
use open ':std';
# Input
my @lines;
open(I, "< desc.txt");
while (my $line = <I>){
chomp($line);
push(@lines, $line);
}
close(I);
# Sort
@lines = sort {$a cmp $b} @lines;
# Output
open(O, "> asc.txt");
foreach (@lines) {
print O "$_\n";
}
close(O);
1;
- 最終更新:2013-05-22 18:02:04