Perl question

Hi
I am trying to issue a system call in my Perl script based on the presence of certain pattern in the other file. The pattern is stored in the variable. Can somebody help me with the syntax. This is an example:

#!/usr/bin/perl
open(MYFILE, "/t1/bin/t1syschk.cmd");
$pattern=cmprsvc;
system "/bb/bin/tsaudba.ksh" if grep /"$pattern"/, <MYFILE>;
close MYFILE;

grep does not handle variable "$pattern"/, but works ok with the constant like grep /cmprsvc/, <MYFILE>;

Thanks a lot for the advice -A

Use:

#!/usr/bin/perl
open(MYFILE, "/t1/bin/t1syschk.cmd");
$pattern="cmprsvc";
system "/bb/bin/tsaudba.ksh" if grep /$pattern/, <MYFILE>;
close MYFILE;

Hi,

This one works:

#!/usr/bin/perl
open(MYFILE, "./TestFile.txt") || die("Could not open file.");
@fileRows=<MYFILE>;
$pattern="TESTPAT";
print "/bb/bin/tsaudba.ksh" if grep(/$pattern/, @fileRows);
close MYFILE;

Thanks a lot, guys. It Worked :slight_smile: