in reply to Re^2: Printing of Array Hash is Missing Elements
in thread Printing of Array Hash is Missing Elements
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
|
|---|