Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find a specific line in a file without using regular expressions in Perl?

I have a file that I want to read in using the File::Slurp module then search that file for a specific line. I know Perl has regular expressions but the strings I’m searching for are user-generated so don’t want to have to worry about escaping everything. I could write a foreach loop to do this but was wondering if there’s a function in Perl that will do this for me? Everything I see online about finding text in Perl uses regular expressions.

like image 542
Jared Avatar asked Dec 05 '25 06:12

Jared


1 Answers

You can just use a regular expression. You don't have to worry about escaping everything, Perl has the quotemeta function for that (or alternatively, "\Q\E").

like image 177
Leon Timmermans Avatar answered Dec 07 '25 20:12

Leon Timmermans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!