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

Brad C

New member
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?
 
Uhhh well first you could read the file handle into an array.

@array = <FILE>;

and then just make a variable equal to 1 if the string is found in each element, and do nothing if it isn't. If the variable equals 1, that means there was a match.

I kind of forgot how to use the match operator, but the basic idea is to just find if there is any true value for the match in ALL of the elements of the array.
 
Uhhh well first you could read the file handle into an array.

@array = <FILE>;

and then just make a variable equal to 1 if the string is found in each element, and do nothing if it isn't. If the variable equals 1, that means there was a match.

I kind of forgot how to use the match operator, but the basic idea is to just find if there is any true value for the match in ALL of the elements of the array.
 
Back
Top