Jason Malburg wrote:
> Hi,
Hello,
> I'm working on a complex data structure with hashes of hashes and
> hashes of arrays and I noticed a weird behavior I was hoping someone
> could explain.
Put these two lines at the beginning of your program:
use warnings;
use strict;
and perl will tell you what is wrong.
> Here's a sample:
>
> $Data{US17}{1}{GROUP} = "STRING";
> $Data{US17}{1}{GROUP}{.001} = 5;
> $Data{US17}{1}{GROUP}{.002} = 6;
> $Data{US17}{1}{GROUP}{.003} = 7;
The scalar $Data{US17}{1}{GROUP} can only hold either a string or a reference,
not both.
$ perl -le'
use warnings;
use strict;
use Data::Dumper;
my %Data;
$Data{US17}{1}{GROUP} = "STRING";
$Data{US17}{1}{GROUP}{.001} = 5;
$Data{US17}{1}{GROUP}{.002} = 6;
$Data{US17}{1}{GROUP}{.003} = 7;
print Dumper \%Data;
'
Can't use string ("STRING") as a HASH ref while "strict refs" in use at -e line
7.
$ perl -le'
use Data::Dumper;
my %Data;
$Data{US17}{1}{GROUP} = "STRING";
$Data{US17}{1}{GROUP}{.001} = 5;
$Data{US17}{1}{GROUP}{.002} = 6;
$Data{US17}{1}{GROUP}{.003} = 7;
print Dumper \%STRING, \%Data;
'
$VAR1 = {
'0.002' => 6,
'0.003' => 7,
'0.001' => 5
};
$VAR2 = {
'US17' => {
'1' => {
'GROUP' => 'STRING'
}
}
};
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/