Alright, so this is what I have:
#!/usr/local/bin/perl
my $argument1 = $ARGV[0];
open (LOGFILE, "<$argument1") or die "Can't find file";
open FILE, ">>output.txt" or die $!;
while(<LOGFILE>){
if (/UNSUCCESSFUL/){
print FILE "ERROR in line $.\n" if (/Error/);
print "script unsuccessful \n";
else:
print "script successful \n"; }
}
close FILE;
close LOGFILE;
The problem, I think, is with my if else statement. If there is not the word “unsuccessful” in the text that is read in, it should simply print out “Script successful.” However, if the read in file does contain “unsuccessful,” then it should record where in the file the word “Error” appears and write this out to a file. Help?!
Sample input:
bar foo bar bar bar
error: will not compile
bar bar bar bar bar
attempt unsuccessful
I assume you do not wish to print
"script successful"for all the lines in your input that does not contain the word"UNSUCCESSFUL". Instead, save the printing for last, and if you have no errors, print the success message.