Re: [Boston.pm] Is there a modifier on m or s that says the argument is not a regex

Steve Tolkin via Boston-pm <[email protected]> Mon, 14 Jan 2019 20:40:14 -0500
Newsgroups gmane.comp.lang.perl.perl-mongers.boston
Message-ID <[email protected]>
Thanks to all -- both suggestions are good.  If I make the time (ha!) I'll try to see if there is a material performance difference.  But I doubt it.
So \Q \E wins by being a little easier to type -- and it has the side benefit that I can use regex in a few cases where what I want to match looks like \d+ etc.

-----Original Message-----
From: Conor Walsh [mailto:[email protected]] 
Sent: Sunday, January 13, 2019 9:57 PM
To: Steve Tolkin <[email protected]>
Cc: Boston PM <[email protected]>
Subject: Re: [Boston.pm] Is there a modifier on m or s that says the argument is not a regex

Steve,

This sounds like a use-case for...  not using regular expressions. :) https://perldoc.perl.org/functions/index.html
https://perldoc.perl.org/functions/substr.html

-C.

On Sun, Jan 13, 2019 at 9:29 PM Steve Tolkin via Boston-pm <[email protected]> wrote:
>
> Is there a modifier for m  that says the argument is not a regular 
> expression?  Similarly for the or the first argument to s?
> I looked and did not find it.
> This seems like it would be useful.
>
> I want to extract certain lines from a log file.  My perl program is 
> basically  lots of lines like:
>
> print if m/some string/;
>
> If the string contains a left or right parenthesis I must escape it or 
> else get an error message that says the argument is "not a regular expression".
>
> So I have to escape each parenthesis with a backslash, which is 
> tedious and error prone.
> I presume I would also need to escape at least the open square 
> bracket, but have not had those in the file.
>
> Also, the string often contains lots of dots, e.g., is 
> com.example.foo/bar/program.c at line(123)  and this requested 
> modifier would have a small performance benefit.
>
> --
> Steve Tolkin
>
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> https://mail.pm.org/mailman/listinfo/boston-pm