blackd77 wrote:
Hello. I want to add sequential numbers to a file, one number per
line, at the end of each line. The files have a .csv format. So, I'd
like to add ",1" to the first line, ",2" to the second line, and so on
(without the quotation marks of course). I have not started building
the code, so there isn't anything to critique yet. I'm just thinking
about how to start, so anything that would point me in the right
direction would be helpful and welcome.

I have thought about something that would combine the pushing of a
value to an array, with some kind of auto-increment routine. Set a
scalar to 1, read line one, split on the commas, push the value onto
the array, increment 1 to 2, move to line two, read line two, split on
the commas, push the value onto the array, increment 2 to 3, move to
line three, etc...

Any suggestions will be helpful. I'll be trying to put a routine
together tomorrow morning. This is probably really simple for the
experts.

perl -pe's/$/",".++$a/e' yourfile



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to