Hi Folks,
I’m still learning PERL and I think I’ve taken a wrong turn.
I’m working on a simple script that needs to check the contents of a file for a certain word. I’ve been playing around with the following code:
open(FNAME, 'c:\Scripts\phile.txt') or die "I can't find your file\n";
@lines = <FNAME>;
close(FNAME);
foreach $line (@lines)
{
if ($line =~ /wordX/ )
{
print "True \n" ;
}else{print "False \n" ;
}
}
exit 0
When I run the script on a four line file, the output contains three “False” and one “True”.
What I need is for the script to return “True” if it finds “wordX” any place in the file and “False” if it doesn’t.
Where did I go wrong?
Thank you for your time.
Peter.
I’m still learning PERL and I think I’ve taken a wrong turn.
I’m working on a simple script that needs to check the contents of a file for a certain word. I’ve been playing around with the following code:
open(FNAME, 'c:\Scripts\phile.txt') or die "I can't find your file\n";
@lines = <FNAME>;
close(FNAME);
foreach $line (@lines)
{
if ($line =~ /wordX/ )
{
print "True \n" ;
}else{print "False \n" ;
}
}
exit 0
When I run the script on a four line file, the output contains three “False” and one “True”.
What I need is for the script to return “True” if it finds “wordX” any place in the file and “False” if it doesn’t.
Where did I go wrong?
Thank you for your time.
Peter.