I have written some code to read in a CSV file and then store various characteristics about network information at each building into a hashed array. I then print it back out to another CSV file, and I'd like to be able to sort the information by building name. However, I'm not there yet as my current code only prints 11 of the 40 total entries in the table. My code is cleaned up for now, but I have previously verified by printing out the hash that it indeed contains all 40 records prior to printing to my output file.

#!c:\perl\bin\perl use strict; use warnings; my %buildings; my $hashref = \%buildings; my $ref; my $vlan_number; my $first_octet; my $second_octet; my $third_octet; my $fourth_octet; my $subnet_slash; my $subnet_dotted; my $network; my $bldg_name; my $description; my $infile = "e:\\IP Addressing Spreadsheet.csv"; open MYFILE,"<$infile" or die "Could not open CSV file! : $!"; + foreach my $line (<MYFILE>) { chomp($line); my @temp = split(/,/,$line); $vlan_number = $temp[0]; $first_octet = $temp[1]; $second_octet = $temp[2]; $third_octet = $temp[3]; $fourth_octet = $temp[4]; $subnet_slash = $temp[5]; $subnet_dotted = $temp[6]; $network = $temp[7]; $bldg_name = $temp[8]; $description = $temp[9]; @temp = (); $buildings{$bldg_name}{'name'} = $bldg_name; $buildings{$bldg_name}{'number'} = $vlan_number; $buildings{$bldg_name}{'first_octet'} = $first_octet; $buildings{$bldg_name}{'second_octet'} = $second_octet; $buildings{$bldg_name}{'third_octet'} = $third_octet; $buildings{$bldg_name}{'fourth_octet'} = $fourth_octet; $buildings{$bldg_name}{'subnet_slash'} = $subnet_slash; $buildings{$bldg_name}{'subnet_dotted'} = $subnet_dotted; $buildings{$bldg_name}{'network'} = $network; $buildings{$bldg_name}{'description'} = $description; } close MYFILE; my $outfile = "e:\\BuildingVLANS.csv"; unlink $outfile; open (OUTFILE,">$outfile") or die "Could not open CSV file! : $!"; print_hash($hashref); close OUTFILE; sub print_hash { $ref = shift; for my $entry (sort keys %buildings) { print OUTFILE "Building name,$ref->{$entry}{'name'}\n"; print OUTFILE "VLAN number,$ref->{$entry}{'number'}\n"; print OUTFILE "VLAN 1st Octet,$ref->{$entry}{'first_octet'}\n"; print OUTFILE "VLAN 2nd Octet,$ref->{$entry}{'second_octet'}\n"; print OUTFILE "VLAN 3rd Octet,$ref->{$entry}{'third_octet'}\n"; print OUTFILE "VLAN 4th Octet,$ref->{$entry}{'fourth_octet'}\n"; print OUTFILE "VLAN Subnet Slash,$ref->{$entry}{'subnet_slash'}\n" +; print OUTFILE "VLAN Subnet Dotted,$ref->{$entry}{'subnet_dotted'}\ +n"; print OUTFILE "VLAN Network,$ref->{$entry}{'network'}\n"; print OUTFILE "VLAN Description,$ref->{$entry}{'description'}\n"; print OUTFILE "\n"; } } __END__

In reply to 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.