On Nov 29, 2005, at 10:42, Bedanta Bordoloi, Gurgaon wrote:

No, $log_entry[0] holds a string, and we are getting the error as ** is a
part of that string.

Interpolation in regexps is done before the regexp is interpreted as such. For instance, if $foo is "*" and we have

    /.*$foo/

first interpolation is done giving

    /.**/

and that is interpreted as a regexp, which in this case is invalid and would raise an error.

In consequence, metacharacters in interpolated strings need to be escaped to be treated literally, and this is easy to get:

    $str =~ s/(^\Q$log_entry[0]\E\s)//i

There we start escaping with \Q, and end it with \E, so that "\s)" is interpreted as part of the regexp as is. If you wanted to escape the very string outside the regexp there's quotemeta().

-- fxn

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to