Store related data together. The only reason to create large parallel arrays is because you are forced to.
If you are concerned about speed and memory usage, you can use constant array indexes to access your named fields:
use constant { SIZE => 0, NAME => 1, VOLUME => 2, }; sub something { ... $ref->[SIZE] = 10; $ref->[NAME] = "Foo"; $ref->[VOLUME] = 100; push @references, $ref; ... return @references; }
I also added some spaces to make the code more readable.
If I have many parameters with validation rules and / or deep data structures, I tend to look at objects to simplify my code by linking data logic to data. Of course, OOP requires a speed penalty, but I rarely saw this as a problem.
For quick and dirty OOP, I use Class :: Struct, which has many drawbacks. In situations where I need type checking, I use Moose or Mouse (when memory or startup speed is very important).
source share