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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Learn Data Structures easy
by brian_d_foy (Abbot) on Feb 06, 2006 at 18:55 UTC | |
|
Re: Learn Data Structures easy
by zshzn (Hermit) on Feb 06, 2006 at 17:13 UTC | |
by demerphq (Chancellor) on Feb 07, 2006 at 09:02 UTC | |
|
Re: Learn Data Structures easy
by talexb (Chancellor) on Feb 07, 2006 at 12:19 UTC | |
|
Re: Learn Data Structures easy
by EvanCarroll (Chaplain) on Feb 15, 2006 at 01:14 UTC |