開発環境
- 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を解いてみる。
その他参考書籍
2.
コード(TextWrangler)
sample.pl
#!/usr/bin/env perl use strict; use warnings; use utf8; use 5.012; binmode STDOUT, ':utf8'; binmode STDIN, ':utf8'; my $dir = "."; chdir $dir or die "can't chdir to $dir: $!"; while(1){ print "パターンを入力: "; chomp(my $pattern = <STDIN>); last if $pattern =~ /^\s*$/; print map{"$_\n"} grep{eval{/$pattern/}} glob "*"; print $@ if $@; }
入出力結果(Terminal)
$ ./sample.pl パターンを入力: pl$ perl_program.pl sample.pl パターンを入力: sample sample sample.pl sample.pl.bak sample.pl.bak.bak sample_folder sample_text sample_text.out sample_text.out.bak パターンを入力: ^[^.]*$ barney betty fred link_test numbers Oogaboogoo perl_kamimura_blog perl_program1 result sample sample_folder sample_text some_folder sortable_hash test_folder test_link tmp_folder パターンを入力: ( Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE / at ./sample.pl line 15, <STDIN> line 4. パターンを入力: [ Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE / at ./sample.pl line 15, <STDIN> line 5. パターンを入力: $
0 コメント:
コメントを投稿