開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也、田中 慎司、吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9) の8章(ファイルハンドルへのリファレンス)、8.6(練習問題)3を解いてみる。
3.
コード(TextWrangler)
#!/usr/bin/env perl use strict; use warnings; use IO::Dir; for(@ARGV){ p($_); } sub p{ my $dir = shift; my $dir_fh = IO::Dir->new($_) || die "can't open dirhandle: $!"; print "$dir\n"; while(defined(my $file = $dir_fh->read)){ print " $file\n"; } }
入出力結果(Terminal)
$ ./sample.pl sample sample_folder test_folder sample . .. .DS_Store sample_folder sample_folder copy sample_folder copy 2 sample_folder copy 3 sample_folder copy 4 sample_folder . .. .DS_Store sample1.bak test test_folder . .. .DS_Store sample $
0 コメント:
コメントを投稿