in reply to Append to beginning of line (multi line file)

Unless I'm much mistaken (which has been known to happen), you're opening the file, reading in the entire thing, closing it, opening it again for appending and writing "$count." to the file once for each line.
As you're appending to the end of the file, thats why the line numbers appear at the end. I don't know (undef) = <FILE> but it doesn't seem to be springing to the beginning of the file, which is what you would need in order to write $count to the beginning.

I suggest you try:
1. Open file, read all lines, close file.
2. Open another filename, write each $count and the line itself to the new file in a loop.
3. Unlink the old file, rename the new one to the old.
You can use @files to get the number of lines also, instead of reading the file again.

C.

Replies are listed 'Best First'.
Re: Append to beginning of line (multi line file)
by FireBird34 (Pilgrim) on Jan 23, 2003 at 23:26 UTC
    Thanks for the input. The reasoning behind the (undef) = <FILE> area, was for a different program I was working on. It was reading through the file and printing out extra info I didn't want. So reading around, I found a small snippit, that after using, seemed to fix my problem. Will look at some of your above examples -- thanks again. (also, I knew some of my code was 'excess', which is why I added that line for suggestions on making it better :))