開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Strawberry Perl (WindowsのPerlの言語処理系)
- Visual Studio Code (Text Editor)
- Perl 5.28 (プログラミング言語)
初めてのPerl 第7版 (Randal L. Schwartz(著)、brian d foy(著)、Tom Phoenix(著)、近藤 嘉雪(翻訳)、嶋田 健志(翻訳)、オライリージャパン)の9章(正規表現によるテキスト処理)、9.6(練習問題)1の解答を求めてみる。
コード
#!/usr/bin/env perl
use strict;
use warnings;
use v5.28;
say '1.';
my $what = shift @ARGV;
while (<>) {
chomp;
if (/($what){3}/) {
say;
}
}
入出力結果(Zsh、PowerShell、Terminal)
% cat sample.txt
Fred
frederick
Alfred
fred flintstone
Mr. Slate
Fred
Mississippi
Bamm-Bamm
llama
wilma
fred
FRED
wilma fred
fred wilma
wilmafred
WilmaFred
barney
Mrs. Wilma flintstone
I saw Wilma Yesterday
I, Wilma!
Fred
fredfredfred
fredfredbarney
barneyfredfred
barneybarneyfred
% ./sample1.pl fred sample1.pl
1.
% ./sample1.pl fred sample.txt
1.
fredfredfred
% ./sample1.pl "fred|barney" sample.txt
1.
fredfredfred
fredfredbarney
barneyfredfred
barneybarneyfred
%
0 コメント:
コメントを投稿