LoginSignup
0
0

More than 5 years have passed since last update.

マッチした文字列の行を出力したい

Posted at

目的

シェルコマンドのgrepのように、マッチした文字列の行を出力したい

環境

CentOS 7

コード

  • perlのgrep関数は期待した結果と異なる為、system関数を使ってシェルコマンドのgrepを呼び出す
  • grepでマッチした文字列があれば、戻り値として0を回答する。以下の例であれば、$return_codeに0またはそれ以外の値が入る
test.pl
use strict;
use warnings;
use utf8;

my $policy = "test";
my $return_code = system("grep $policy target.txt > data.txt");

if($return_code ne 0) {
    exit;
}
    print "次の処理を続ける"
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0