Because you are keying your hash by building name, you only get 4 hash entries, one for each unique building name. Each time you add a new line with the same building name, it overwrites the last line you inserted for that building entry. Hence you read in 40 lines but only get out 4.

If you want to keep each row separate, I would recommend storing your parsed records in an array of hashes and using a customized sort function.

Instead of $buildings{bldg_name}{first_octet} do something like this:

my @aBuildings; while (my $line=<MYFILE>) { chomp $line; #... parse line # add a new element to your array of hashes (AoH) my $hLine = { name => $bldg_name number => $vlan_number ... }; push @aBuildings, $hLine; }

Then in your print out you would use a custom sort to sort the array elements by building name:

foreach my $hLine (sort { $a->{name} cmp $b->{name} } @aBuildings) { #print out contents of $hLine }

See sort and perldsc for more information about custom sorting routines and AoH (array of hash) data structures.

Best, beth


In reply to Re^3: Printing of Array Hash is Missing Elements by ELISHEVA
in thread Printing of Array Hash is Missing Elements by spickles

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.