[Kc] List of Lists
joe at radiojoe.org
Fri Sep 17 02:13:06 CDT 2004
On Thu, 16 Sep 2004 at 9:04pm -0500, jyoung79 at kc.rr.com wrote:
> Hello everyone,
> I've been researching through my Perl books, etc. and can't figure out
> how to create a list of lists. Here's what I'm trying to do:
The key is knowing how anonymous data structures work. If you know
the basics you can easily create very complex data structures.
For instance, try this:
my @data = ( [ 0..4 ],
[ 5..9 ],
apple => 'red',
smurf => 'blue'
[ 10..14 ],
[ 15..19 ],
So the first element in the @data array, is an anonymous array holding
the value 0 through 4, the second element is another anonymous array
holding 5 through 9, the third element in the list is an anonymous
hash, and so on and so forth.
If you haven't used Data::Dumper before, it can give you a very nice
idea of how your data structure is layed out. (Plus the output is
valid perl, so it can be handy if you are doing experiments.)
> From everything I've read so far though, it doesn't look like it's
> possible to make this list of lists.
Remember that `perldoc perl` and `perldoc perltoc` both have a nice
index of the included perl documentation.
In particular, you should read `perldoc perllol`, which specifically
deals with lists of lists), and `perldoc perlreftut`, which is a more
in depth look at complex data structures.
More information about the kc