Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Bretheren, I seek your guidance. I have read the scriptures but have not found enlightenment. No doubt the answer is there but I understand not the wisdom. I beg thine assistance. (Ok...I'll cut that out. :p)

I have a flat file (with some 185k lines)with values like the following:
"CHEVY","US","UNITED STATES" "MERCEDES","DE","GERMANY" "PEUGOT","FR","FRANCE" "FORD","US","UNITED STATES" "LADA","RU","RUSSIAN FEDERATION" "SATURN",US","UNITED STATES" "ROLLSROYCE","UK","UNITED KINGDOM "BMW","DE","GERMANY" <c> </p> As the file is read via a while() loop I'm putting the country code (i +.e. US, DE, etc.) into a hash.</p> <c> while(<DB>) { @db = split/,/; push(@countries,$db["1]); }

I need to do the following:

  1. If the country code is not in the hash, add it with a value of 1;
  2. If the country code is in the hash, increment the value by 1;
  3. When all the entries are in the hash sort it so that it prints out from highest to lowest.

My questions:

1) Is a hash the proper structure for what I'm trying to do?

2) If so, how do I get it to do what I'd like?

Thank you in advance for your help. My experience is at the beginner level and I sincerely appreciate your help.


ElMagnifico - I work at it so that maybe one day it'll be true! :-D

20080205 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

In reply to Need help on hashes. by ElMagnifico

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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (14)
    As of 2019-10-22 16:51 GMT
    Find Nodes?
      Voting Booth?