Keep in mind that your assignment is totally broken. Missing equals sign aside, see what this does:
my @array = (%hash1, %hash2);
What you end up with is merely a list of the key/value pairs from
%hash1 and
%hash2, not an array of hashes.
As
hardburn suggested, what you want is a hash of hashes (HoH):
use warnings;
use strict;
my @template;
my %data;
while (<>)
{
chomp;
my @line = split(/\|/, $_);
if (!@template)
{
@template = @line;
}
else
{
my $key = lc($line[2]."_".substr($line[1],0,1));
@{$data{$key}}{@template} = @line;
}
}
use Data::Dumper;
print Dumper(\%data);
I really have no idea how you were going to name your hashes like that, so I guessed. Note that you might have to fix the
$key definition so that two "B.Smith" people don't collide.