Home > Archive > PERL Beginners > November 2006 > perl string substitution
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
perl string substitution
|
|
|
| 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
| |
|
| In article <woCdnWOfy9AzqvXYRVnyvw@eclipse.net.uk>,
"John" <john1949@yahoo.com> 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>
Boyd
| |
|
| Hi
Many thanks.
When I tried it myself it didn't work but clearly it does. I may have put a
backslah before the $.
Anyway, thanks again.
Regards
John
"boyd" <tbmoore9@verizon.net> wrote in message
news:tbmoore9-5D568E.08074425112006@news.verizon.net...
> In article <woCdnWOfy9AzqvXYRVnyvw@eclipse.net.uk>,
> "John" <john1949@yahoo.com> wrote:
>
>
> 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>
>
> Boyd
| |
| nobull67@gmail.com 2006-11-25, 9:58 pm |
|
John wrote:
> "boyd" <tbmoore9@verizon.net> wrote in message
> news:tbmoore9-5D568E.08074425112006@news.verizon.net...
>
> 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.
|
|
|
|
|