The $_[0]->[0][0][0] syntax for recovering data is not too bad.

I would disagree with that. This looks very obtuse to me! I think that a much better data structure can be constructed. It would be helpful if we backed up and talked about what data you need for each experiment. It sounds like this will wind up being a hash with different values having perhaps reference to list or scalar or simple string or perhaps ref to another hash.

I would go as far as to say that having an array with heterogeneous data types is a bad idea. One of the "power hitter" features of Perl is that it has very cool iteration functions. Most of the time, it is not even necessary to know the "index" of some individual item at all! This is because instead of say a traditional "for loop" ala for (i=1;i<30;i++){work with a[i]}we have foreach my $thing (@a){do something with thing}. You want each thing in an array to be the same so that these array iterators work well.

Anyway for each experiment, %experiment, say, perhaps:

$experiment{'title'}='some text'; $experiment{'data'}= [data set]; $experiment{'test condx'}= some ref to another hash table $experiment{'date run'}='some date';
If you want to group experiments all together, then it could be that a ArrayOfHash (AoH), is the right way.

Anyway I think a VAST simplification of your data structure can be made which will result in a VAST improvement in the readability of the code.

So instead of debating how to make your existing syntax work, I suggest backing up to requirements and then proceeding with a data struct based upon that info.

Some small points, you don't need &function() to call function anymore, function(...blah) does it!

Update:
I wrote some simple code as a demo of how a LoH (list of hash) would work...it illustrates a couple of points: 1) nowhere in the code is any kind of [$i] variable! 2)Rather than "going deeper" to make new data sets, this uses the Regex power of Perl to keep things flat - if the key contains 'data' then the key represents a list of stuff.

#!/usr/bin/perl -w use strict; my %experiment1 = ( 'title' => "some title 1", 'data' => [ 1, 2, 3, 4, 5, 6], 'data2' => [10, 11, 12], ); my %experiment2 = ( 'title' => "some title 2", 'data' => [ 100, 101, 103,], 'data2' => [200, 300, 400], 'data3' => [500, 600, 700], ); my @experimentDB = (\%experiment1, \%experiment2); print_all_experiment_titles(\@experimentDB); print "printing dataset(s) for all experiments\n"; print_all_data(\@experimentDB); sub print_all_experiment_titles { my $ref_LoH = shift; foreach my $href (@$ref_LoH) { print "$href->{'title'}\n"; } } sub print_all_data { my $ref_LoH = shift; foreach my $href (@$ref_LoH) { foreach my $key2Lref (sort grep {/data/} keys(%$href)) { print "@{$href->{$key2Lref}}\n"; } } } __END__ The above prints: some title 1 some title 2 printing dataset(s) for all experiments 1 2 3 4 5 6 10 11 12 100 101 103 200 300 400 500 600 700

In reply to Re: multiple layers of referencing and dereferencing by Marshall
in thread multiple layers of referencing and dereferencing by Bruce32903

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.