Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in array of hashes

Status
Not open for further replies.

theSeeker03

Programmer
Jan 16, 2004
17
US
I have a tab delimited file that I want to read in, such that each line is a hash and the entire file is an array of the hashes. To test it, I am printing a CityName. What's wrong with this picture?:

my @arrayOfContacts;
my $numOfContacts =0;
while (<INCONT>){
chomp($_);
$arrayOfContacts$numOfContacts]{&quot;CONT_ID&quot;,
&quot;ADDR_1&quot;,&quot;ADDR_2&quot;,&quot;CITY_NAME&quot;}= split(/\t/,$_);
$numOfContacts++;
}

print &quot;$numOfContacts\n&quot;;
print &quot;$arrayOfContacts[$numOfContacts]{CITY_NAME}\n&quot;;
 
Sorry, I meant

$arrayOfContacts[$numOfContacts]{&quot;CONT_ID&quot;,

with the bracket [
 
In order to assign the values to your hash slice, you need to treat it as a list:
[tt]@{$arrayOfContacts[$numOfContacts]}{&quot;CONT_ID&quot;, &quot;ADDR_1&quot;, &quot;ADDR_2&quot;, &quot;CITY_NAME&quot;} = split(/\t/);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top