bagel has asked for the wisdom of the Perl Monks concerning the following question:

My code is at http://24.167.156.45 it accepts 2 inputs for the log file (access_log) and something to search for (127.0.0.1) and then commences to replace it. I did this by having the file fed into an array and substituting the matching lines with "". The only problem is since these are GET requests in a log ?, *, + show up often but PERL complains out. Any solution?
  • Comment on How to escape out *?+ in strings for substit.

Replies are listed 'Best First'.
Re: How to escape out *?+ in strings for substit.
by japhy (Canon) on Jul 12, 2001 at 08:12 UTC
    Use either the quotemeta() function, or the \Q...\E escape sequences.
    $string =~ /\Q$text\E/; # or $safe = quotemeta $text; $string =~ /$safe/;