2020年5月8日金曜日

開発環境

初めてのPerl 第7版 (Randal L. Schwartz(著)brian d foy(著)Tom Phoenix(著)近藤 嘉雪(翻訳)嶋田 健志(翻訳)、オライリージャパン)の7章(正規表現)、7.10(練習問題)6の解答を求めてみる。

コード

#!/usr/bin/env perl
use strict;
use warnings;
use v5.28;

say '6.';

while (<>) {
    chomp;
    # 一つ目の方法
    if (/wilma/) {
        if (/fred/) {
            say;
        }
    }
    # 他の方法
    if (/wilma.*fred|fred.*wilma/) {
        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
% ./sample6.pl sample.txt 
6.
wilma fred
wilma fred
fred wilma
fred wilma
wilmafred
wilmafred
%

0 コメント:

コメントを投稿