From: sln on
On Thu, 01 Jul 2010 16:47:51 -0700, sln(a)netherlands.com wrote:

>Or you can combine it all in a double eval regex as something like this:
>(expanded with print for detail)
>
>$i = 2;
>$string =~ s/(test)(string)/print '${'.$i."}\n"; '${'.$i.'}'/ee;
># or, shortened
># $string =~ s/(test)(string)/'$'.$i/ee;
>

Or, another popular notation:

$string =~ s/(test)(string)/"\$$i"/ee;

-sln
From: sln on
On Thu, 01 Jul 2010 23:23:32 +0100, Big and Blue <No_4(a)dsl.pipex.com> wrote:

>On 07/01/10 17:29, Tad McClellan wrote:
>
>>
>> $string=~s/(test)/test/;
>>
>> I smell an XY-problem.
>>
>> What is it that you are actually trying to accomplish?
>
>Is it, by chance:
>
>my $i=1;
>my $string="teststring";
>$string=~s/(?<test>test)/$+{test}/;
>print "$string\n";
>
>?

This is equivalent to the trivial solution as there is no need
for $i. In that case s/test/test/ is faster.

-sln
From: yjnnhauhht on
On Jul 2, 2:00 am, s...(a)netherlands.com wrote:
> On Thu, 01 Jul 2010 16:47:51 -0700, s...(a)netherlands.com wrote:
> >Or you can combine it all in a double eval regex as something like this:
> >(expanded with print for detail)
>
> >$i = 2;
> >$string =~ s/(test)(string)/print '${'.$i."}\n"; '${'.$i.'}'/ee;
> ># or, shortened
> ># $string =~ s/(test)(string)/'$'.$i/ee;
>
> Or, another popular notation:
>
> $string =~ s/(test)(string)/"\$$i"/ee;
>
> -sln

Thanks!
This answer my needs.
From: yjnnhauhht on
On Jul 2, 12:23 am, Big and Blue <N...(a)dsl.pipex.com> wrote:
> On 07/01/10 17:29, Tad McClellan wrote:
>
>
>
> >      $string=~s/(test)/test/;
>
> > I smell an XY-problem.
>
> > What is it that you are actually trying to accomplish?
>
> Is it, by chance:
>
> my $i=1;
> my $string="teststring";
> $string=~s/(?<test>test)/$+{test}/;
> print "$string\n";
>
> ?
>
> --
>               Just because I've written it doesn't mean that
>                    either you or I have to believe it..

This doesn't solve my issue, cause I need to do the thing in a for
loop where the $i is incremented.
Thanks for your time though.
From: yjnnhauhht on
On Jul 2, 3:39 pm, yjnnhauhht <yjnnhau...(a)mailinator.com> wrote:
> On Jul 2, 12:23 am, Big and Blue <N...(a)dsl.pipex.com> wrote:
>
>
>
> > On 07/01/10 17:29, Tad McClellan wrote:
>
> > >      $string=~s/(test)/test/;
>
> > > I smell an XY-problem.
>
> > > What is it that you are actually trying to accomplish?
>
> > Is it, by chance:
>
> > my $i=1;
> > my $string="teststring";
> > $string=~s/(?<test>test)/$+{test}/;
> > print "$string\n";
>
> > ?
>
> > --
> >               Just because I've written it doesn't mean that
> >                    either you or I have to believe it.
>
> This doesn't solve my issue, cause I need to do the thing in a for
> loop where the $i is incremented.
> Thanks for your time though.

Well what I really want to do is some kind of "highlighting grep -E"
which highlights the part of the match pattern that is inside ().
For example if I do mygrep "...\w*(test)..." file, I get the lines
matching the pattern and the word test is highlighted.
To do this I have to add a highligth/nohighligth control string before
and after each () group.
I though I will be able to do this in one regex, but failed and only
found a solution where I need to iterate on the () groups and do the
s/.../$i/ I ask you about.