5
以下のコードで複数の列にまたがって並べ替えを行う方法はありますか?複数の列を並べ替える(Perl)
現在、コード:
1. $directory
2内のファイルの@list
を取得しますが@list
3.プリントアウト3つの値の中で各要素の$fileName
、$fileLocation
と$fileSize
を取得するために正規表現を使用します
1. $fileName
:(2)3固定幅の列 4にそしてIが出力によってソートされた表示したいファイルやディレクトリのサイズ
の総数を印刷その後、
2. $fileLocation
その後、
3. $fileSize
$directory = '/shared/tmp';
$count = 0;
@list = qx{du -ahc $directory};
printf ("%-60s %-140s %-5s\n", "Filename", "Location", "Size");
foreach(@list) {
chop($_); # remove newline at end
if (/^(.+?K)\s+(.+\/)(.+\.[A-Za-z0-9]{2,4})$/) { # store lines with valid filename into new array
# push(@files,$1);
$fileSize = $1;
$fileLocation = $2;
$fileName = $3;
if ($fileName =~ /^\./) {
next; }
printf ("%-60s %-140s %-5s\n", $fileName, $fileLocation, $fileSize);
$count++;
}
else {
next;
}
}
print "Total number of files: $count\n";
$total = "$list[$#list]";
$total =~ s/^(.+?)\s.+/$1/;
print "Total directory size: $total\n";