How do I parse a file in Perl for a string?

martinthurn

New member
use strict;
use warnings;
use File::Slurp;
my $sContents = read_file(q{filename.txt});
if ($sContents =~ m/string of text/)
{
print "true";
}
else
{
print "false";
}
__END__
 
I'm very new to Perl and learning what I can. One thing I haven't been able to find out is how to parse a file for a string of text and return a simple "true" or "false" if the string is found. I appreciate all your help!
While I believe Slurp would work, are there any built in features that can accomplish this?
 
Back
Top