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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |