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

Dum Spiro Spero

In reply to Re: Need Help with foreach statement????? by GotToBTru
in thread Need Help with foreach statement????? by brawal128

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.