I'm doing a very simple task, loading a file into a hash. The file is a basic zip-code table:
00601PR787ADJUNTAS 00602PR787AGUADA 00603PR787AGUADILLA 00604PR787AGUADILLA 00605PR787AGUADILLA 00606PR787MARICAO 00610PR787ANASCO 00611PR787ANGELES 00612PR787ARECIBO 00613PR787ARECIBO
And the code is pretty straight-forward:
$count = 0; open (ZIPCODE, "<../Files/ZipCodes.txt") or die "Cannot open ZipCode: +$1\n"; while (<ZIPCODE>) { chomp; ($Zip) = substr($_,0,5); ($State) = substr($_,5,2); ($AreaCode) = substr($_,7,3); ($City) = substr($_,10); $ZipDB{$Zip} = "$City|$State|$AreaCode"; $count++; } print "\nStored: $count\n"; $count = 0; foreach $Zip (%ZipDB) { print "$Zip = [$ZipDB{$Zip}]\n"; $count++; } close (ZIPCODE); print "\n$count Zip codes found\n";
When the "foreach" loop runs I get 20 records listed instead of 10:
Stored: 10 00611 = [ANGELES|PR|787] ANGELES|PR|787 = [] 00612 = [ARECIBO|PR|787] ARECIBO|PR|787 = [] 00603 = [AGUADILLA|PR|787] AGUADILLA|PR|787 = [] 00610 = [ANASCO|PR|787] ANASCO|PR|787 = [] 00606 = [MARICAO|PR|787] MARICAO|PR|787 = [] 00601 = [ADJUNTAS|PR|787] ADJUNTAS|PR|787 = [] 00602 = [AGUADA|PR|787] AGUADA|PR|787 = [] 00605 = [AGUADILLA|PR|787] AGUADILLA|PR|787 = [] 00613 = [ARECIBO|PR|787] ARECIBO|PR|787 = [] 00604 = [AGUADILLA|PR|787] AGUADILLA|PR|787 = [] 20 Zip codes found
I am at a total loss as to why this is not working. Mike

In reply to Odd hash problem by wpahiker

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.