234 10 Transforming with Traditional Programming Languages
A 0.222 C 0.407 T 0.074 G 0.296
Summary
- One can represent complex data structures by nesting arrays and hashes,
for example, by constructing an array of hashes, - To keep the data structure simple, it is convenient to use only hashes.
- Individual elements of a nested data structure are obtained by using it as
a multidimensional data structure. - To process all of the elements of a nested data structure use a series of
loops nested within each other. - When printing numbers, one can specify how much precision will be used
by using the formatted print statement,printf.
10.2 Transforming XML
This section introduces techniques for transforming XML. It builds on the
techniques of the first section, but new concepts are also required. The first
subsection introduces the notion of a Perl module which allows one to extend
the basic Perl language with new features. Several such modules are then
used to process XML files and to produce them. The processing of XML
is covered first and producing XML is covered second. As in section 10.1,
processing can be performed either as it is encountered, one XML element
at a time, or in some other order, by means of a data structure. XML can
be produced starting from text or from XML. Transforming XML to XML is
especially important and it will be considered again in chapter 11.
10.2.1 Using Perl Modules and Objects
Perl has a mechanism for grouping together variables and procedures into
separate units. In fact, it has several mechanisms for doing this, but they
are very similar to one another. This idea is closely related to the notion of
areferencethat was mentioned in subsection 10.1.2. There is a distinction
between a collection of entities and a collection regarded as a single unit.
The examples in that section consisted of arrays and hashes so these were