For beginners non-cgi issues, there is also the '[EMAIL PROTECTED]'
list. Just for your info....

> While this is being used in a cgi, it's really more of a general perl 
> question.  But I'm hoping I can get some help.
> 
> I have a hash which has arrays of arrays as the value for each key:
> $tabset = 'clientInfo';
> %tabsets = (
>       clientInfo      => [('#', 'View Contact Information', 'Contact 
> Information'),
>                                       ('#', 'View the Job Log', 'Job Log'),
>                                       ('#', 'View the Client Assets', 'Client 
> Assets'),
>                                       ('#', 'View Press Releases', 'Press Releases')
>                                       ],
>       ); # data simplified and other keys removed...
> 

As your questions below state the above "lists" are getting flattened
into one array.  You need to reuse [] to build anonymous array
references like you did in the outer structure. So you end up with:

%hash = (  'key1' => [  [ '#1-1', 'View1-1', 'Title1-1' ],
                        [ '#1-2', 'View1-2', 'Title1-2' ],
                        ...,
                     ],
           'key2' => [  [ '#2-1', 'View2-1', 'Title2-1' ],
                        [ '#2-2', 'View2-2', 'Title2-2' ],
                        ...,
                     ],
           ...,
        );

This will build the structure you describe, where each hash key has a
value that is an array reference, then each element of that array is
itself an array reference with 3 elements.  Use [] instead of () to
derive an array reference.

> I want to be able to first get the array of arrays that matches a key, 
> keeping it as an array of arrays., then do a for each loop, keeping 
> access to the array of that array item (OK, bad description, I know...):
> 
> (here's where things go awry)
> 
> if (exists($tabsets{$tabset})) {
>       my @$tabs = @{$tabsets{$tabset}}; #this isn't right....
> 

Nope, you are dereferencing an array into a non-existent dereferenced
array ref. I assume $tabset has been assign properly, lest the 'exists'
fails. In other words, where did you get $tabs? If you can answer that
then it might be right, but since you can't (I presume) it isn't.... so
simplify it to,

my @tabs = @{$tabsets{$tabset}};

Be sure to turn on 'use strict' and it will help you catch mistakes like
this. 

>       foreach my @tab (@tabs) { #of course this isn't correct syntax, but 
> should illustrate what I intend to do


So switch it to be correct, once your dereference above is correct:

foreach my $tab (@tabs) {

Ok now what does $tab contain?  It is an element of the first array, and
how did we describe it above... right it is an array reference. So, you
can either dereference it all together,

my @inner = @$tab;

But that seems silly because Perl provides a more elegant solution:

>               print "<a href=\"$tab[0]\" title=\"$tab[1]">$tab[2]</a>\n";

The above would be correct if you used the $inner[0], but rather than
explicitly dereferecing, we can use the elegant -> construct:

print "<a href=\"$tab->[0]\">$tab->[2]</a>\n";

Obviously I changed your line, but you get the picture....

>       }
> } else {
>       &explode();
> }
> 
> 
> 
> What really happens will be a bit more complex, but that is the basic 
> logical structure is what I want.  But I rapidly get confused in what's 
> a reference, and how to refer to something without flattening my 
> 2-dimensional array into a flat array (so that the above array with 4 
> items which are each an array of 3 items ends up being a single array 
> of 12 items).
> 
> So, the questions are, how do I handle the references so I can maintain 
> the 2-dimensional-ness of my hash values, but still access them by key, 
> and then how do I use each item, which is an array, in a foreach loop?
> 

See inline above. You may be better enlightened by looking at the
following docs:

perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref

And to help you building your complex data structures be sure to have a
look at Data::Dumper which is very handy for making sure you really have
what you wanted....

HTH, welcome to a whole new world...

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to