"Moon, John" <[EMAIL PROTECTED]> writes: > I have the follows code > perl -e ' > @a=(q{a...x name=taga_1 #...d name=tagb_1 f...r name=tagc_1 xxnn}, > q{h...e name=taga_4 t...g name=tagb_4 k name=tagc_4 nn}); > $ndx = 0; > foreach $ln (@a) { > print "b4 = $ln\n"; > $ln =~s/(name=.*)\d+/\1$ndx/g; ^
There's your problem - the '*' is 'greedy' by default - in other words, in the first example, the '.*' is matching: taga_1 #...d name=tagb_1 f...r name=tagc_ You could, instead of '.', use \D (not-a-digit): $ln =~s/(name=\D*)\d+/\1$ndx/g; Which produces the output you want. -RN > print "af = $ln\n"; > $ndx++ > }' > Which produces: > b4 = a...x name=taga_1 #...d name=tagb_1 f...r name=tagc_1 xxnn > af = a...x name=taga_1 #...d name=tagb_1 f...r name=tagc_0 xxnn > b4 = h...e name=taga_4 t...g name=tagb_4 k name=tagc_4 nn > af = h...e name=taga_4 t...g name=tagb_4 k name=tagc_1 nn > > I would like to produce: > > b4 = a...x name=taga_1 #...d name=tagb_1 f...r name=tagc_1 xxnn > af = a...x name=taga_0 #...d name=tagb_0 f...r name=tagc_0 xxnn > b4 = h...e name=taga_4 t...g name=tagb_4 k name=tagc_4 nn > af = h...e name=taga_1 t...g name=tagb_1 k name=tagc_1 nn > > Any help will be greatly appreciated. > jwm -- Robin Norwood Red Hat, Inc. "The Sage does nothing, yet nothing remains undone." -Lao Tzu, Te Tao Ching -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>