開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、8章(正規表現によるマッチ)の8.10(練習問題)2.を解いてみる。
その他参考書籍
8.10(練習問題)2.
コード(BBEdit, Emacs)
sample189.pl
#!/usr/bin/env perl # use diagnostics; use strict; use warnings; use 5.016; use utf8; binmode STDIN, ':utf8'; binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; while (<>) { chomp; if (/a\b/) { say "Matched: |$`<$&>$'|"; } else { say "No match: |$_|"; } }
入出力結果(Terminal)
$ ./sample189.pl barney No match: |barney| Mrs. Wilma Flintstone Matched: |Mrs. <Wilma> Flintstone| $ cat temp.txt A a kamimura's blog http://sitekamimura.blogspot.com KMI http://www.mkamimura.com frederick Wilma Alfred Wilma fred flintstone Wilma Wilmaerick AlWilma Wilma flintstone Mr. Slate Mississippi Bamm-Bamm wilama barney Fred and Wilma Wilma and Fred Fred and Wilma Wilma and Fred Fred&Wilma Mrs. Fred Flintstone I saw Fred yesterday I, Fred! Z llama fred $ ./sample189.pl temp.txt No match: |A| Matched: |<a>| Matched: |<kamimura>'s blog| Matched: |http://<sitekamimura>.blogspot.com| No match: |KMI| Matched: |http://www.<mkamimura>.com| No match: |frederick| Matched: |<Wilma>| No match: |Alfred| Matched: |<Wilma>| No match: |fred flintstone| Matched: |<Wilma>| No match: |Wilmaerick| Matched: |<AlWilma>| Matched: |<Wilma> flintstone| No match: |Mr. Slate | No match: |Mississippi| No match: |Bamm-Bamm | Matched: |<wilama>| No match: |barney| Matched: |Fred and <Wilma>| Matched: |<Wilma> and Fred| Matched: |Fred and <Wilma> | Matched: |<Wilma> and Fred| Matched: |Fred&<Wilma>| No match: |Mrs. Fred Flintstone | No match: |I saw Fred yesterday| No match: |I, Fred!| No match: |Z| Matched: |<llama>| No match: |fred| $
0 コメント:
コメントを投稿