On Wed, Jun 13, 2001 at 04:09:29PM -0400, F.H wrote:
[snip]
> $ssns{$ssn}{hobbies}[0][2] which should yield H3
> $ssns{$ssn}{hobbies}[3][0] to get HG.
[snip]
> if ($key =~ /^Hobbies/i) {
> push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line];
> }
>From this, your data structure is:
%ssns = (
'123-43-4352' => {
'hobbies' => [qw(
JX 1234 SKI BaseBall swimming H1 H2 H3 HH HHH HHHH2 H1 H43
)],
...
},
...
);
But you're trying to access it as:
$ssns{'123-43-4352'}{'hobbies'}[0][2];
You have one index too many. To get 'H3' you'd use:
$ssns{'123-43-4352'}{'hobbies'}[7];
If you want to preserve the line numbers you need to push an array
reference:
if ($key =~ /^Hobbies/i) {
push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
}
Your data structure would then look like this:
%ssns = (
'123-43-4352' => {
'hobbies' => [
[qw(JX 1234 )],
[qw(SKI BaseBall swimming)],
[qw(H1 H2 H3 )],
[qw(HH HHH HHHH2 )],
[qw(H1 H43 )],
)],
...
},
...
);
Then you'd be able to access 'H3' as:
$ssns{'123-43-4352'}{'hobbies'}[2][2];
You have commented lines in your script for printing out the data structure
using Data::Dumper. This is a good idea, and ideal for determining why your
accesses aren't getting the data you want.
> __DATA__
> Name ,123-43-4352, JX, 1234
> Sports,123-43-4352, SKI, BaseBall, swimming
> Hobbies, 123-43-4352, H1,H2, H3
> Hobbies, 123-43-4352, HH, HHH, HHHH2
> Hobbies,123-43-4352, H1,H43
>
> Name ,223-63-9352, JX, 1234
> Sports,223-63-9352, SKI, BaseBall, swimming
> Hobbies, 223-63-9352, H1,H2, H3
> Hobbies, 223-63-9352, HH, HHH, HHHH2
> Hobbies,223-63-9352, H1,H43
> Hobbies,223-63-9352, HG, HG, HGFR
I sincerely hope these aren't real social security numbers.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--