syphilis has asked for the wisdom of the Perl Monks concerning the following question:
I expected $str1 and $str2 to be identical after the substitution regexes, but they're not (on both perl-5.16.0 and 5.20.0 at least). For me, the demo outputs:#!perl -l use strict; use warnings; my $orig = 'a.dll'; my $replacement = 'b.dll'; my $str1 = "foo $orig bar"; my $str2 = $str1; $str1 =~ s/\Q$orig\E/\Q$replacement\E/g; $str2 =~ s/\Q$orig/$replacement/g; print $str1; print $str2;
Why does the first regex put that backslash in there ?foo b\.dll bar foo b.dll bar
$str1 would then have become foo b\.dll, whereas I expected foo b.dll.$str1 =~ s/\Q$orig\E.+/\Q$replacement\E/g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A misunderstanding of quotemeta ?
by LanX (Saint) on Jun 04, 2014 at 02:44 UTC | |
by syphilis (Archbishop) on Jun 04, 2014 at 03:42 UTC | |
|
Re: A misunderstanding of quotemeta ?
by Athanasius (Archbishop) on Jun 04, 2014 at 02:52 UTC | |
|
Re: A misunderstanding of quotemeta ?
by AnomalousMonk (Archbishop) on Jun 04, 2014 at 04:13 UTC |