Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-20 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found