in reply to multiple layers of referencing and dereferencing

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

Replies are listed 'Best First'.
Re^2: multiple layers of referencing and dereferencing
by Bruce32903 (Scribe) on Jun 23, 2009 at 11:26 UTC
    I responded to "not too bad" in an earlier reply.

    Thank you for the suggestions and sample code. I'm printing it and thinking about how I can reorganize my approach to my actual task to take advantage of these "better ways". I like the much cleaner look of it, but I'm going to need a little time to "see the light" for my application.

    Thank you
      Perl has amazing capabilities to generate very complex multi-dimensional data structures. In Perl every dimension until the last one is a reference. Seldom will more than 3 dimensions be needed with the power of the built in data type of hash table especially when combined with Regex. In my example, instead of making a sub-struct with the "data", I just filtered the hash keys to get the "data" keys (data,data1,data3) instead of other keys. This "flattens" the code and reduces one level in the data structure (and very efficiently).

      I looks like to me that you just need a hash table with some heterogeneous values, like pointer to array, scalar, etc. This single structure is then represented in an amalgamation as an array them (pointers, "references" to them).