You're not thinking (or expressing yourself) carefully enough to get thoughtful answers. You'll get a few good guesses maybe, but correct solutions, probably not (unless someone gets lucky). Here are the unanswered questions we would need to help you with a correct solution:
- Does your input file really have a header row and a row of hyphens?
- Does your input file use fixed-width fields, or space-delimited fields? (If fixed-width, why didn't you demonstrate fixed width? If not, you've got a new problem.)
- If your input file uses space-delimited fields, how does it handle compound names? (Names that consist of more than one word)
- You say that a first name or a last name can be used as the lookup for a single person in the list. And in the sample data set you provided it appears that would be fine. But in the real world neither first names, nor last names, nor combinations of first and last names are actually unique; you cannot reasonably expect that a name search will result in a single result. So what should happen when there are first name collisions, last name collisions, or first/last collisions?
- You ask "...what if there are many names in the file." ...yes, what if? How many is many? How big could the file be? How often does the file change? Could we sort it once? Should we be maintaining an index file parallel to the actual data file? We can't answer these questions because we don't know enough about the problem you're solving.
Each of the solutions you've been provided fail to deal with compound names and name clashes. Neither of them scale particularly well either. But they're both just fine for your limited sample input. This illustrates the point that brief sample input that doesn't show the breadth of possible input, combined with an incomplete description of the problem can lead to answers that seem fine, but will fail in real use.
If this is a school assignment, go back to the professor and get answers to these questions so that you can more carefully craft a correct solution. If it's a work project, then you should know enough about your client to be able to answer these questions. If you don't, you need to nail down the spec with your client better.
Only then can you begin to produce a useful solution. And until the details are known that can lead to a useful solution, there's no point in anyone wasting time giving you solutions based on guess work or incomplete specifications, because they will miss some detail that is crucial to the client or to your professor.
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.