If you need a bigger answer you need to paint a bigger picture. There are many ways to speed up searches, and they all depend on what you are searching for, how big the hay stack is, what you are going to do when you find each item and how many items there are. Good techniques also depend on whether the file is sorted, how big the keys are, how much ancillary data there is, is the file across a network, on local disk or in memory, and probably a slew of other thing.

The best thing you can do is describe the bigger picture - 20,000 records are not very many so most likely there is something in your bigger process that you are doing inefficiently. It's unlikely to be a Perl construct, it's much more likely to be of the nature of needlessly nested loops (quite possibly the grep you mentioned) or something of that nature.

We have a sample of your data. Now describe what you need to do with it.


Perl reduces RSI - it saves typing

In reply to Re: Needed Performance improvement in reading and fetching from a file by GrandFather
in thread Needed Performance improvement in reading and fetching from a file by harishnuti

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.