Hi,
Let me just clarify that in this loop where it doesn't work:
foreach $i ( 0 .. $#{ $ssns{$ssn}{hobbies} } ) {
print " $ssns{$ssn}{hobbies}[$i]";
}
I need to be able to access through maybe a multidemensional array each elemnt of the
hobbies.
Thanks
I.S
[EMAIL PROTECTED] (F.H) wrote:
>
>
> Michael,
> Thanks for taking the time to solve this problem. Of course those are not real ssn
>numbers.
> I tried your suggestion:
>
> ....
> if ($key =~ /^Hobbies/i) {
> push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
> }
> }
>
> # print results
> print "\n TEST: $ssns{'123-43-4352'}{'hobbies'}[2][2]\n";
> It came out with no results and down below in the foreach loop:
> It printed:
> Hobbies are:
> ARRAY(0xca6840) ARRAY(0xca6828) ARRAY(0xca67f8) ARRAY(0xca67a4)
>
> Did I miss/skip something in the code?
> Regards
>
> I.S
>
> Michael Fowler <[EMAIL PROTECTED]> wrote:
> >
> > 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
> > --
> >
> __________________________________________________________________
> Get your own FREE, personal Netscape Webmail account today at
>http://webmail.netscape.com/
>
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at
http://webmail.netscape.com/