Using a sequential integer as the key for your hashes %firms and %acs is a give-away that you really want an array, not a hash.
my (@firms); while (defined( my $line = <FH1> ) ){ chomp $line; my (%hash); my ($type, $location1, $location2, $label) = split ',', $line, 12; $hash{type} = $type; $hash{label} = $label; push @firms, \%hash; }
Update: suggestion for a more compact way to extract the data from array of hashes for uploading (using an hash slice):
@fields=qw(name64 label location1 subnet support_radius); for(my $i=0; $i<=$#firms; $i++) { $firms[$i]->{subnet} /= 32; $upload .= sprintf "%s\n", join ',', @{$firms[$i]}{@fields}; }
Update 2: as pointed out by Albannach, the commas did not belong in the array definition
In reply to Re: Need Help with foreach statement?????
by GotToBTru
in thread Need Help with foreach statement?????
by brawal128
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |