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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.