2012年7月23日月曜日

開発環境

『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也田中 慎司吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9) の9章(リファレンスを使った実践的なテクニック)、9.9(練習問題)1を解いてみる。

1.

コード(TextWrangler)

#!/usr/bin/env perl
use strict;
use warnings;

my @sorted = 
  map $_->[0],
  sort{ $a->[1] <=> $b->[1] } 
  map [$_, -s $_],
  glob "/bin/*";

for(@sorted){
  print "$_\n";
}

入出力結果(Terminal)

$ ls -l /bin/*
-r-xr-xr-x  2 root  wheel    43120 10 16  2011 /bin/[
-r-xr-xr-x  1 root  wheel  1371648 10 16  2011 /bin/bash
-r-xr-xr-x  1 root  wheel    44192 10 16  2011 /bin/cat
-r-xr-xr-x  1 root  wheel    62768 10 16  2011 /bin/chmod
-r-xr-xr-x  1 root  wheel    57808 10 16  2011 /bin/cp
-rwxr-xr-x  1 root  wheel   772992 10 16  2011 /bin/csh
-r-xr-xr-x  1 root  wheel    57408 10 16  2011 /bin/date
-r-xr-xr-x  1 root  wheel    61216  2  2 17:46 /bin/dd
-r-xr-xr-x  1 root  wheel    52432 10 16  2011 /bin/df
-r-xr-xr-x  1 root  wheel    34672 10 16  2011 /bin/domainname
-r-xr-xr-x  1 root  wheel    34608 10 16  2011 /bin/echo
-r-xr-xr-x  1 root  wheel   122000 10 16  2011 /bin/ed
-r-xr-xr-x  1 root  wheel    43808 10 16  2011 /bin/expr
-r-xr-xr-x  1 root  wheel    34720 10 16  2011 /bin/hostname
-r-xr-xr-x  1 root  wheel    35088 10 16  2011 /bin/kill
-r-xr-xr-x  1 root  wheel  2180736 10 16  2011 /bin/ksh
-r-xr-xr-x  1 root  wheel   167472  5 10 10:15 /bin/launchctl
-r-xr-xr-x  2 root  wheel    39600  2  2 17:46 /bin/link
-r-xr-xr-x  2 root  wheel    39600  2  2 17:46 /bin/ln
-r-xr-xr-x  1 root  wheel    80752  2  2 17:46 /bin/ls
-r-xr-xr-x  1 root  wheel    35072  2  2 17:46 /bin/mkdir
-r-xr-xr-x  1 root  wheel    44848  2  2 17:46 /bin/mv
-r-xr-xr-x  1 root  wheel   243104  2  2 17:46 /bin/pax
-rwsr-xr-x  1 root  wheel    95840 10 16  2011 /bin/ps
-r-xr-xr-x  1 root  wheel    34704 10 16  2011 /bin/pwd
-r-sr-xr-x  1 root  wheel    66368 10 16  2011 /bin/rcp
-r-xr-xr-x  2 root  wheel    44528  2  2 17:46 /bin/rm
-r-xr-xr-x  1 root  wheel    34624  2  2 17:46 /bin/rmdir
-r-xr-xr-x  1 root  wheel  1371712 10 16  2011 /bin/sh
-r-xr-xr-x  1 root  wheel    34688 10 16  2011 /bin/sleep
-rwxr-xr-x  1 root  wheel    64976 10 16  2011 /bin/stty
-r-xr-xr-x  1 root  wheel    34288 10 16  2011 /bin/sync
-rwxr-xr-x  1 root  wheel   772992 10 16  2011 /bin/tcsh
-r-xr-xr-x  2 root  wheel    43120 10 16  2011 /bin/test
-r-xr-xr-x  2 root  wheel    44528  2  2 17:46 /bin/unlink
-r-xr-xr-x  1 root  wheel    34576  5 10 10:15 /bin/wait4path
-rwxr-xr-x  1 root  wheel  1103984 10 16  2011 /bin/zsh
$ ./sample.pl
/bin/sync
/bin/wait4path
/bin/echo
/bin/rmdir
/bin/domainname
/bin/sleep
/bin/pwd
/bin/hostname
/bin/mkdir
/bin/kill
/bin/link
/bin/ln
/bin/[
/bin/test
/bin/expr
/bin/cat
/bin/rm
/bin/unlink
/bin/mv
/bin/df
/bin/date
/bin/cp
/bin/dd
/bin/chmod
/bin/stty
/bin/rcp
/bin/ls
/bin/ps
/bin/ed
/bin/launchctl
/bin/pax
/bin/csh
/bin/tcsh
/bin/zsh
/bin/bash
/bin/sh
/bin/ksh
$

0 コメント:

コメントを投稿