If your concern is just in keeping the names in the same order in which they're seen, there are two approaches. The easiest is to look into Tie::IxHash. This is a variant of the hash that preserves the order of keys as they are inserted.

The second way, that doesn't require installing a new module, is to have your loop also push all newly-discovered names onto an array, then use the array to iterate over the hash rather than the keys keyword.

Don't be so quick to dismiss the basic constructs that Perl provides. They are here for a reason, and when you ask a very basic question you have to expect that your initial answers are going to be pointers to the these basic elements. At the very least, if you are going to ask such a basic question then you should state up front why you don't want to use the basic solution.

--rjray


In reply to Re: Re: Re: Counting incidents of names in a file by rjray
in thread Counting incidents of names in a file by Bishma

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.