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
.



Relevant Pages

  • Re: How to pass string in command line argument.
    ... Perl Pra wrote: ... i have perl script that searches given string (the string should be passed ... The string should be sent to the script with double quotes attached to it ...
    (perl.beginners)
  • Re: How to pass string in command line argument.
    ... >>> my perl script is something like this ... >>> just a straight string is geeting passed ... >>> but i need to send the entire string including double quotes to the ...
    (perl.beginners)
  • Re: Comments requested: brief summary of Perl
    ... >of Perl. ... When converting a string to a number, only the characters up to the first nonnumeric ... | Assignment is done with the = sign, as seen above, and you can use an assignment statement ... Within single quotes, the only ...
    (comp.lang.perl.misc)
  • Re: Changing date field in a text file...
    ... > you understand a little more about the Perl language. ... > seeing those quotes anyway. ... Those two digits will be the day number. ... The regular expression is the contents of the first pair ...
    (comp.unix.shell)
  • Re: Changing date field in a text file...
    ... you understand a little more about the Perl language. ... But the shell "eats" quotes before sending the rest to Perl. ... Those two digits will be the day number. ... The regular expression is the contents of the first pair ...
    (comp.unix.shell)