Re: perl string substitution




John wrote:

"boyd" <tbmoore9@xxxxxxxxxxx> wrote in message
news:tbmoore9-5D568E.08074425112006@xxxxxxxxxxxxxxxxxxx
In article <woCdnWOfy9AzqvXYRVnyvw@xxxxxxxxxxxxxx>,
"John" <john1949@xxxxxxxxx> wrote:

Hi

In string substiution can those two patterns be strings, such as

my ($a,$b,$c);
$a="some string"; $b="another string";
$c =~ s/$a/$b/g;

Thanks
John

Yes. You can easily try this for yourself. Start up the perl debugger
with perl -de1. Here is a session I did to test your question:
DB<1> $a = 'this'

DB<2> $b = 'that'

DB<3> $c = 'this is a string'

DB<4> $c =~ s/$a/$b/g

DB<5> print $c
that is a string
DB<6>

Many thanks.

Please show your gratitude by refaining from TOFU.

When I tried it myself it didn't work but clearly it does. I may have put a
backslah before the $.

Note, without a \Q then the contents of $a is interpreted as a regex
not as a literal string.

.



Relevant Pages

  • Cant Compiling perl5.8.8 on FreeBSD6.2
    ... WITH_DEBUGGING=yes Build perl with debugging support. ... First let's make sure your kit is complete. ... What is the file extension used for shared libraries? ... I'll use sprintf to convert floats into a string. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: use of DBI; I am getting multiple error messages mixed in with ?the correct output.
    ... But I'm not talking about C++ or Java or SQL. ... This is a perl newsgroup. ... to means by a "defined null string", as opposed to an undefined value. ... And where exactly are you getting the idea that the empty string is a ...
    (comp.lang.perl.misc)
  • Re: Perl Strings vs FileHandle
    ... Just wanted to run this through Perl gurus to see if fit is ... testing it every time through the loop. ... The comparison test to the string '1' is superfluous. ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (comp.lang.perl.misc)
  • Re: How to get "perl -V"s output programmatically?
    ... JB> Sometimes I agree with her regexp-less solutions. ... Sadly I miss some of the Perl fun, ... especially not for contains literal string ... sure you can do many string things without regexes, ...
    (comp.lang.perl.misc)
  • Re: Working with Source Code to Insert Copyright Statements as a Header
    ... Paul Lalli wrote: ... Where could I go to find some samples of PERL code that do the ... ascii english text, etc etc etc) at the top of the file, from a string: ... `perldoc Tie::File` at the command line to read its documentation. ...
    (comp.lang.perl.misc)