On Jun 21, Brent Clark said:
Hi all
Would anyone be so kind as to look at my code.
Im trying to create a hash of hashes
while(<DATFILEREAD>){
chomp;
@linex = split(/\|/);
You should have 'my' in front of @linex; there's no reason to use a global
variable there.
my %xmlData = (
[snipped]
);
You could have saved yourself some effort by writing that as:
my %xmlData;
@[EMAIL PROTECTED] = @linex;
where @hash_keys is an array you've defined at the beginning of your
program that contains the keys of your hash in the specific order as they
relate to the elements of @linex:
my @hash_keys = qw(
bbookdate bbooktime bstayf
...
bbillcode bpuphhmm brethhmm
);
And why does every hash key start with 'b'? That just seems a little
silly to me.
%fullXmlHash{$xmlData{'bbookref'}} = %xmlData;
}
Your syntax is wrong here. Here are a couple ways you could write this:
%{ $fullXmlHash{$xmlData{'bbookref'}} } = %xmlData;
or
$fullXmlHash{$xmlData{'bbookref'}} = \%xmlData;
I would suggest the second one, since it doesn't *copy* the contents, it
takes a reference to them. You also don't need the quotes around the hash
key 'bbookref' if it's a simple string (no whitespace or non-alphanumeric
characters):
$fullXmlHash{$xmlData{bbookref}} = \%xmlData;
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>