There was a similar question posted here a few days ago. It boils down to this: Perl cannot know where, within a file, "Confname" occurs, without first skimming through the file to find "Confname". Similarly, it cannot know where line 34 begins, how many characters are in the 3000th line, or any other internal file information, without first skimming through the file to find out.

This fact is not constrained to Perl. It is true of any programming language, given the same scenario: find "Confname" in a file. It's a fact that is not even constrained to just the world of computers.

Quick, find me the 23rd occurrence of the word "Radley" in To Kill a Mockingbird, but do so without opening the book, and without skimming your way through the book. It's not possible.

A good piece of advice when thinking through a problem is to think of how you might do it yourself, without a computer. And then program the computer to do what you would have done. If it were you, yourself, looking for "Confname" in a document, you would physically skim through the document looking for that word.

That said, your existing snippet is probably the simplest way to do just that. If you find that the simple solution fails to meet your needs in some way, think of how you would improve the situation in the non-computer world. Maybe after you found "Confname" for the first time, in the non-computer world, you would put a bookmark on the proper page of the document. In the computer world, you might maintain an index file to accomplish the same efficiency.


Dave


In reply to Re: moving the filehandle to anyline of a file by davido
in thread moving the filehandle to anyline of a file by jesuashok

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.