The advice I would give you then is that hashes are for context and arrays are for order.
Things that you don't need to know the order of should be in some sort of hash because the keys of a hash give the data context. Example:
my @cats = qw(persian siamese cute);
my @dogs = qw(doverman bulldog);
## Bad data structure
my @data = (\@cats, \@dogs);
function( \@data );
## Good data structure
function1({
cats => \@cats,
dogs => \@dogs,
});
The first example with a bad data structure requires explicit know of the exact order of your arguments to know where cats and dogs are. In addition if you just deference the data you still don't necessary know what you are working with. Don't do it.
The second example explicitly designates which array references go with what type of data. Your funtion() will need to deference the data via a name which puts your code into a context which makes it easier to understand.
sub function1 {
my $params = shift;
warn "My Dogs\n";
for (@{$params->{'dogs'}}) { warn "\t$_\n" }
warn "My Cats\n";
for (@{$params->{'cats'}}) { warn "\t$_\n" }
}
Hope this helps. |