Home
Search Perl pages
Subjects
By activity
Professions, Sciences, Humanities, Business, ...
User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...
Text Strings
Conversions, tests, processing, manipulation,...
Math
Integer, Floating point, Matrix, Statistics, Boolean, ...
Processing
Algorithms, Memory, Process control, Debugging, ...
Stored Data
Data storage, Integrity, Encryption, Compression, ...
Communications
Networks, protocols, Interprocess, Remote, Client Server, ...
Hard World Timing, Calendar and Clock, Audio, Video, Printer, Controls...
File System
Management, Filtering, File & Directory access, Viewers, ...
|
|
|
perldsc - Perl Data Structures Cookbook
perldsc - Perl Data Structures Cookbook
The single feature most sorely lacking in the Perl programming language
prior to its 5.0 release was complex data structures. Even without direct
language support, some valiant programmers did manage to emulate them, but
it was hard work and not for the faint of heart. You could occasionally get
away with the $m{$LoL,$b} notation borrowed from awk in which the keys are actually more like a single concatenated string "$LoL$b" , but traversal and sorting were difficult. More desperate programmers even
hacked Perl's internal symbol table directly, a strategy that proved hard
to develop and maintain--to put it mildly.
The 5.0 release of Perl let us have complex data structures. You may now
write something like this and all of a sudden, you'd have a array with
three dimensions!
for $x (1 .. 10) {
for $y (1 .. 10) {
for $z (1 .. 10) {
$LoL[$x][$y][$z] =
$x ** $y + $z;
}
}
}
Alas, however simple this may appear, underneath it's a much more elaborate
construct than meets the eye!
How do you print it out? Why can't you say just print @LoL ? How do you sort it? How can you pass it to a function or get one of these
back from a function? Is is an object? Can you save it to disk to read back
later? How do you access whole rows or columns of that matrix? Do all the
values have to be numeric?
As you see, it's quite easy to become confused. While some small portion of
the blame for this can be attributed to the reference-based implementation,
it's really more due to a lack of existing documentation with examples
designed for the beginner.
This document is meant to be a detailed but understandable treatment of the
many different sorts of data structures you might want to develop. It
should also serve as a cookbook of examples. That way, when you need to
create one of these complex data structures, you can just pinch, pilfer, or
purloin a drop-in example from here.
Let's look at each of these possible constructs in detail. There are
separate sections on each of the following:
|
(Corrections, notes, and links courtesy of RocketAware.com)
Rapid-Links:
Search | About | Comments | Submit Path: RocketAware > Perl >
perldsc/index.html
RocketAware.com is a service of Mib Software Copyright 2000, Forrest J. Cavalier III. All Rights Reserved. We welcome submissions and comments
|