開発環境
- 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) の2章(中級者の基礎知識), 2.4(練習問題)2を解いてみる。
1.
コード(TextWrangler)
#!/usr/bin/env perl
use strict;
use warnings;
my $dir = "/etc";
chdir $dir or die "can't change directory to $dir:$!";
while(1){
print "パターンを入力: ";
chomp(my $pattern = <STDIN>);
last if $pattern =~/^\s*$/;
print "ファイル一覧\n";
print map{" $_\n"} grep{eval{/$pattern/}} glob(".* *");
}
入出力結果(Terminal)
$ ./sample.pl
パターンを入力: [
ファイル一覧
パターンを入力: (
ファイル一覧
パターンを入力: ^a
ファイル一覧
afpovertcp.cfg
aliases
aliases.db
amavisd.conf.default
apache2
asl.conf
authorization
authorization~previous
auto_home
auto_master
auto_master~orig
autofs.conf
パターンを入力: a$
ファイル一覧
パターンを入力: b$
ファイル一覧
aliases.db
gettytab
krb5.keytab
rmtab
xtab
パターンを入力:
$
0 コメント:
コメントを投稿