On Mar 23, 2004, at 9:32 AM, juman wrote:

Not sure I understand what you say here...

Should I do this then?

$data = "question?"
$newdata = m/\Q$data\E/

I believe you meant:


$newdata =~ m/\Q$data\E/;

Hope that helps.

James

Because I couldn't get that to work?

/juman

On Tue, Mar 23, 2004 at 09:03:15AM -0600, James Edward Gray II wrote:
On Mar 23, 2004, at 8:54 AM, juman wrote:

I have a script that handles some text strings. The textstrings in them
self I can't control so they can contain characters as ?:>< etc which
makes them hard to check through a regexp. So I want to replace alla
characters like this:


question? => \q\u\e\s\t\i\o\n\?

Hopefully that would make things easier for me matching them but how do
I do this?

Here's a one liner that answers your question directly:


perl -e '$str = "question"; $str =~ s/(.)/\\$1/g; print "$str\n"'

But, don't do that.  There is a special escape just for escaping the
regex characters.  You want:

m/\Q$your_variable_here\E/

Hope that helps.

James


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





--
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