vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

use Data::Dumper; my $find="REE (.*) vinoth"; my $replace= "ree $1 VINOTH"; my $var = "REE is alias of vinoth"; $var =~ s/$find/$replace/ee; print Dumper $var;

In the above code I expect "REE is alias of vinoth" replace to "ree is alias of VINOTH" but I did not get What I expect, I was getting output as  $VAR1 = ''; What is happening here ?

Vinoth,G

Replies are listed 'Best First'.
Re: find and replace
by lakshmananindia (Chaplain) on Apr 11, 2009 at 08:13 UTC

    Simple! That happens because of interpolations. Try assigning as follows

    my $replace= '"ree$1VINOTH"';

    You can also do that in regular expression like

    my $find="REE (.*) vinoth"; my $replace= 'ree$1VINOTH'; my $var = "REE is alias of vinoth"; $var =~ s/REE (.*) vinoth/'"'.$replace.'"'/ee;
    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.


Re: find and replace
by AnomalousMonk (Archbishop) on Apr 11, 2009 at 09:07 UTC