53 lines (31 with data), 3.2 kB
:!podchecker Piddle.pod && pod2html --infile=Piddle.pod --outfile=Piddle.html
open Piddle.html and click 'reload'
conversion for PDF reading is:
pod2pdf Piddle.pod --icon-scale 0.25 --title "PDL Book" --icon logo2.png --output-file Piddle.pdf
=head1 What is a Piddle?
PDL uses Perl `objects' to hold PDL data, affectionately called a piddle. An `object' is like a user-defined data-type and is a very powerful feature of Perl, PDL creates it's own class of `PDL' objects to store piddles. These look like ordinary Perl variables such as $x, $Foo, $MyData, etc.
Most of the time you can forget about the fact that piddles are objects and treat them like ordinary variables:
$x = rfits 'file.fits';
$y = rvals($x);
$z = $x/$y;
The only time the distinction becomes important is when creating piddles and using the `=' operator.
=head2 Piddles are NOT Perl `arrays'
It is now time to answer a question which has probably been nagging at the back of your mind for a while.
Why bother with piddles? Why not just use normal Perl `arrays'?
By Perl `arrays' we of course mean entities like @x and @Data z which one would normally create and manipulate like this:
@x = (1,2,3);
push @x, 42;
$y = pop @x;
So why don't we just use Perl `arrays'? Several very good reasons:
It is impossible to manipulate Perl `arrays' arithmetically as one would like. i.e.:
@y = @x * 2; # Wrong!
can not be made to operate element by element.
Perl `arrays' are really what are known in computer science as `lists' (and are represented internally by a list data structure). In fact if the PDL-Porters had their evil way they would ban the term `array' from all of the standard Perl documentation and books. This is why the term `piddle' was invented for use in PDL for what we think really are `true arrays'.
Perl lists are intrinsically one-dimensional. You can have `lists of lists' but this is not the same thing as true multi-dimensional arrays. Honest.
Perl lists consume a lot of memory. At least 20 bytes per number, of which only a few are for the actual value. This is because Perl lists are flexible, and can contains text strings as well as numbers. This flexibility requires an internal complex data structure which contains extra information such as a place holder for the number, a place holder for the text and pointers forward and back along the list.
Perl lists are scattered about memory. The list data structure means consecutive numbers are not stored in a neat block of consecutive memory addresses as C and FORTRAN programmers are used to. This makes it difficult to pass the arrays to low-level C and FORTRAN routines for processing -- the numbers must be collected together -a process known as `packing' -- processed and unpacked back into lists. If you have `lists of lists' then it get's even worse.
Perl lists do not support the range of data types that piddles do (byte arrays, integer arrays, single precision, double precision, etc.)
That is why PDL does not use Perl lists. Just to be clear from now on we'll always refer to PDL numeric data arrays as `piddles' and Perl-style number/text arrays as `lists'.