<> wrote:
> On Fri, 13 Mar 2009 21:48:55 -0500, Tad J McClellan <> wrote:
>
>> <> wrote:
>>> On Fri, 13 Mar 2009 17:42:34 -0500, Tad J McClellan <> wrote:
>>>
>>
>>>>> In the nut of it, evaling a variable with a value '$str'
>>>>> will work,
>>>>
>>>>
>>>>Because the value is a valid Perl expression.
>>>>
>>>>
>>>>> but with a value of '$str\n$str' will not.
>>>>
>>>>
>>>>Because the value is not a valid Perl expression.
>>
>>
>>> Oh, I get it. Its all about "valid expression"
>>
>>
>>You're welcome.
>
> No thanks! But you are welcome.
>
> Here's some valid expression for ya Tad:
>
> $replacement2 = '$2';
> $data =~ /(.)\n(.)/;
> $e = eval ($replacement2);
> print "->",$e,"\n";
>
> $data =~ s/(.)\n(.)/$replacement2/eg;
> print $data."\n";
That works as expected. Since there is only one eval with s///e,
the result after evaluating $replacement2 is the string '$2'.
What were you expecting it to do instead?
If you were expecting the last print to print the value of the $2
variable, then you don't have enough levels of eval to get to where
'$2' is evaluated.
The 2nd level of eval can be gotten with either
$data =~ s/(.)\n(.)/$replacement2/eeg;
or
$data =~ s/(.)\n(.)/$e/eg;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"