Hi Parag, a few comments on your code.
On Sat, 3 Sep 2011 23:38:31 -0700 Parag Kalra <paragka...@gmail.com> wrote: > use strict; > use warnings; > while(<DATA>){ You should expect the contents of the file to be in a different place than __DATA__, so one should use open or *ARGV or whatever here. > my $num = $. - 1; This is not needed because one can use the /e flag to s///. You may wish to have a counter that is external to the loop to keep consistency and not rely on line numbers. > s/\d+/$num/ if /\w+\s+\d+\s+\w/; The problem here is that: 1. The regular expression match is not anchored to the beginning of the line. 2. The substitution won't work properly if the first field contains digits. A better way to do it would be: s/\A(\S+\s+)\d+(\s+\S)/$1 . ($. - 1) . $2/e; Regards, Shlomi Fish > print $_; > } > > __DATA__ > charith 4 matara > saman 8 kandy > andrew 9 colombo > dilshan 3 galle > shanil 10 jafna > > > Parag > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/ Microsoft — making it all make sense. Ours. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/