Re: ARGV interpretation in s///



Paul Lalli <mritty@xxxxxxxxx> wrote:

> I'm hoping someone else in this group can explain to me why this works,
> or better yet, why *doesn't* a simple single /e without the extra
> double quotes, or even a /ee without the extra double quotes. Why are
> the two evals and the double quotes all necessary?


The replacement string part of s/// is double quotish (by default),
ie. with implied double quotes.

So, (with the implied quotes shown) it looks like this to perl:

"$Replace"

perl does the indicated interpolation to determine the string to
use as the replacement.


Using the s///e modifier changes the above mentioned default so
that the replacement part is code rather than a string.

In that case, perl sees:

$Replace

so it evaluates that (simple) expression, no interpolation going on here.


With s///ee, the 1st eval sees:

$Replace

as in the s///e case above. After evaluating that, the 2nd eval sees:

FOO$1BAR

bareword, variable, bareword. And confusion ensues.


So, adding the double quotes to the value in $Replace would make
the 2nd eval see:

"FOO$1BAR"

perl does the indicated interpolation to determine the string to
use as the replacement.



Note that, though it doesn't apply in this case since the values
are coming from the command line anyway, but what would the
2nd eval is s///ee see (and evaluate) if $Replace should
ever get a value like:

$Replace = 'unlink <* .*>';

??


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.