The Data Structures are of a bit complex to understand but it very powerful in storing huge records. Have a look at the data structures explained very easy.
There are many kinds of nested data structures. The simplest kind to build is an array of arrays, also called a two-dimensional array or a matrix.
@array = ( ['a','b'], ['c','d'], ['e','f'] ); print $array[1][0]; #result c;
An array of hashes is useful when you have a bunch of records that you'd like to access sequentially, and each record itself contains key/value pairs.
@array = ( { 'a'=>'b', 'b'=>'c' }, { 'c'=>'d', 'd'=>'e' }, { 'e'=>'f', 'f'=>'g' } ); print $array[1]{c}; #result d;
Use a hash of arrays when you want to look up each array by a particular string rather than merely by an index number.
%hash = ( "1" => ['a','b'], "2" => ['c','d'], "3" => ['e','f'], ); print $hash{1}[0]; result a
A multidimensional hash is the most flexible of Perl's nested structures. It's like building up a record that itself contains other records.
%hash = ( "1" => { 'a'=>'b', 'b'=>'c' }, "2" => { 'c'=>'d', 'd'=>'e' }, "3" => { 'e'=>'f', 'f'=>'g' } ); print $hash{2}{d}; #result e
Moved from Q & A to Meditations by Arunbear
In reply to Learn Data Structures easy by l.frankline
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |