Ah, OK. First you're getting the size of the file with the -s test. Then you're reading in the entire file with read---now the file position is at the very end of the file. Now, when you say "seek back 1700 characters from the current position", you're saying 1700 characters from the end of the file, since the file position is at the end of the file.

I think you want to use the pos function, which will tell you where in the string the last match happened. Since you've read the entire file, the positions in the string will be equal to the positions in the file, so you can just seek to the position that pos returns.

As others have suggested, though, you should consider using an HTML parser. HTML parsing is hard, and other people have already done it.


In reply to Re: Re: Re: Files! Reading specific parts by sgifford
in thread Files! Reading specific parts by wizard341

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.