You may want to consider looping through @ARGV so you can get more than one input argument.

Showing you how to do it would be far easier then pointing you in the right direction, but here's my thoughts...

You can't build a table of contents until you know what page the sections are on.
You can't build an index to key words until you know what page the keywords are on.
And finally you don't know what page you're on until you squeeze the words into the given line length and squeeze the lines into the given lines per page and account for new sections.

So off the top, you're going to have to read the entire file before you can write the contents, so you should be thinking about how you're going to store the file data in variables.

I would think about reformatting each line as you read it to fit the chars/line restriction.
I would think about keeping a running page counter as you read through the file.
I would think about counting words and keeping a list of page numbers for each word.

In reply to Re: Formatting Text by ruzam
in thread Formatting Text by lollipop7081

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.