Jenda Krynicky wrote:
> From: "John W. Krahn" <[EMAIL PROTECTED]>
>> David Gilden wrote:
>>>
>>> How do get  $i do increment inside the substitution below?
>>>
>>> #!/usr/bin/perl -w
>>>
>>> my $i = 0;
>>>
>>> while(<>)
>>> {
>>> chomp;
>>> s/name=\"order/name=\"order$i++/;
>>> print "$_\n";
>>> }
>>
>> Another way to do it:
>>
>> s/name="order/name="order@{[$i++]}/;
>>
>> John
>
> Hey you are right. Let's go crazy:
>
> use Interpolation '=' => 'eval';
> s/name="order/name="order$={$i++}/;
>
> or even worse
>
> use Interpolation 0.69 'incI:->$' => sub {$i++};
> s/name="order/name="order$incI/;
>
>
> The first creates a tied hash for which
> $={$x} eq $x
> for any $x. The second a tied scalar that increments $i each time you
> read its value.

Perhaps more usefully:

    $s =~ s/(?<=name="order)/$i++/e;

Cheers,

Rob







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to