The above replaces the single-quotation mark with bbb. The result will
be:
aaa bbb ccc
How do I modify it so that the single-quotation mark is replaced with
\' (a backslash and a single-quotation mark) resulting in:
aaa \' ccc
Escape it.
$string = "aaa ' ccc ";
$string =~ s/'/\\'bb/; #why are you using /eg?
print $string;
aaa \'bb ccc
sorry.. should have removed 'bb' there.
$string =~ s/'/\\'/;
Because of the /e option you are evaluating the string 'bbb' as though
it were perl code. Why are you doing that?
> The above replaces the single-quotation mark with bbb. The result will
> be:
> aaa bbb ccc
>
> How do I modify it so that the single-quotation mark is replaced with
> \' (a backslash and a single-quotation mark) resulting in:
> aaa \' ccc
$string =~ s/'/\\'/g;
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
$string =~ s/'/\\'/g;
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
Hmmm, for me the result was
Bareword "bbb" not allowed while "strict subs" in use at ...
Which is not surprising because why on earth are you evaluating 'bbb'?
And why are you applying the substitution globally although there is
only one quote sign in the text?
>How do I modify it so that the single-quotation mark is replaced with
>\' (a backslash and a single-quotation mark) resulting in:
>aaa \' ccc
Just put the new text there. Just remember that the desired backslash is
the escape character. Therefore if you want a literal backslash in the
result, then you have to escape the escape character. Oh, and get rid of
those bogus options, too:
$string =~ s/'/\\'/;
jue
To enter a literal backslash, use two backslashes.
--
Lars Eighner <http://larseighner.com/> use...@larseighner.com
Bush's third term begins Jan. 20th with an invocation by Rick Warren.
Obama: No hope; No change; More of the Same.
$string =~ s/'/\\'/;
Thanks guys. I thought I did the above and got Internal Server Error.
I did it again and it is working. Thanks.
B> Thanks guys. I thought I did the above and got Internal Server Error.
B> I did it again and it is working. Thanks.
you should not debug your programs via a web server. that is making it
much harder for you. run the scripts locally on your dev box and then
upload to your server. and don't say you don't have perl on your box
because you can install it easily. and don't say you can't test web
programs on your box because again, you can set up a web server on your
box with little effort. and the term internal server error should be never
be used in a perl group as it is a web server issue. report the actual
perl bug by running it outside a web server
uri
--
Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------