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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.