I have the following code:
What I am trying to do is look through one text file that has the results of a system-run PS command based off of another text file that keeps track of all commands/programs ever run by PS for some experimentation I am doing for college. In my $search_results variable I am attempting to store the result of that search. I use qx() to start up grep. Instead though of grep returning the instance of the search_result,It's like grep returns the entire contents of the file and I dont know why. I have tested the searches in command line and they come up with results I am looking for, but when I run them in the way I have it in Perl, it returns the entire contents of the original text file that I searched. You guys have any ideas on how I can search a text file in Perl in a straightforward manner in Perl? I have looked into Regular Expressions, but I am not sure how I would approach this yet. Any help would be appreciated. Thanks in advance!
P.S. Ignore some of the comments I have in there right now. The comments are actually my goal for what I want a line to do. If you have any ideas let me know as well!
open (epiphanyInput,"input2.csv");
my(@epi_list)=<epiphanyInput>; #read file into list
my($epi_list_line); #declare a line reader so that when you loop you can grab results
#Read in the second file for writing to
open (epiphanyOutput,"+>>Epiphany_results.txt");
my(@epi_result)=<epiphanyOutput>;
my($epi_result_line);
#This code goes through file input from one list and if it's not found in
#Epiphany results it is put into the Epiphany results file.
foreach $epi_list_line(@epi_list){
$search_result=qx(grep "$epi_list_line" Epiphany_results.txt);
#print $search_result;
#print $epi_list_line;
#If these are equal, do nothing at all,else write out to the file the name of the program
if(lc($epi_list_line) eq lc($search_result)){
print "0";
}
if(lc($epi_list_line) ne lc($search_result)){
#print "2";
print epiphanyOutput "$epi_list_line";
}
What I am trying to do is look through one text file that has the results of a system-run PS command based off of another text file that keeps track of all commands/programs ever run by PS for some experimentation I am doing for college. In my $search_results variable I am attempting to store the result of that search. I use qx() to start up grep. Instead though of grep returning the instance of the search_result,It's like grep returns the entire contents of the file and I dont know why. I have tested the searches in command line and they come up with results I am looking for, but when I run them in the way I have it in Perl, it returns the entire contents of the original text file that I searched. You guys have any ideas on how I can search a text file in Perl in a straightforward manner in Perl? I have looked into Regular Expressions, but I am not sure how I would approach this yet. Any help would be appreciated. Thanks in advance!
P.S. Ignore some of the comments I have in there right now. The comments are actually my goal for what I want a line to do. If you have any ideas let me know as well!