Pdl Cribsheet


Installation on Windows

Installation on Ubuntu


To get apropos/help functionality working in the in the PerlDL shell, extract scantree.pl out of the source archive and put into your ActiveState \Perl\site\lib\PDL\Doc directory and run it.

Apropos command may still throw error in PerlDL:

Can't locate object method "interpolate" via package
"Pod::Text" at C:/Perl/site/lib/PDL/Doc/Perldl.pm line 152.

Just commenting out this line seems to fix the problem and online docs work fine.

PGPLOT can't find it's fonts in the default installation. Got to Control Panel-> System Properties -> Advanced -> Environment Variables and add a new System Variable called PGPLOT_FONT that points to where grfont.dat is. Eg. PGPLOT_FONT=C:\Perl\bin\grfont.dat. Restart shell to update environment


  • Byte: byte() 1byte 0-255
  • Unsigned short integer: ushort() 2bytes 0-65535
  • Short integer: short() 2bytes -32768-32767
  • Long integer: long() 4bytes -2147483648-2147483647
  • IEEE single-precision floating point: float() 4bytes
  • IEEE double precision floating point: double() 8bytes

PerlDL Shell

  • Execute a script: do 'script'

Useful commands

  • .= Special assignment operator for element by element arithmetic.
  • append append two or more piddles by concatenating along their first dimensions $c = $a->append($b);. See also glue.
  • at Returns a single value inside a piddle as perl scalar. $z = at($piddle, @position); $z=$piddle->at(@position);
  • clump "clumps" several dimensions into one large dimension
  • dims Return piddle dimensions as a perl list
  • inplace Flag a piddle so that the next operation is done 'in place'. somefunc($x->inplace); somefunc(inplace $x);
  • isifnite Sets $mask true if $a is not a NaN or inf (either positive or negative). Works inplace.
  • list Convert piddle to perl list. @tmp = list $x;
  • mv Move a dimension to another position
  • nelem Return the number of elements in a piddle
  • rcols() Read ASCII whitespaced cols from a file into piddles and perl arrays
  • rvals Fills a piddle with radial distance values from some centre.
  • sclr return a single value from a piddle as a scalar. $val = $a(10)->sclr; $val = sclr inner($a,$b); The sclr method is useful to turn a piddle into a normal Perl scalar. Its main advantage over using at for this purpose is the fact that you do not need to worry if the piddle is 0D, 1D or higher dimensional. sclr is generally used when a Perl scalar is required instead of a one-element piddle. If the input is a multielement piddle the first value is returned as a Perl scalar.
  • sequence Create array filled with a sequence of values
  • zeroes Construct a zero filled piddle from dimension list or template piddle.


use PDL;
use PDL::Graphics::PGPLOT;
# Available PGPLOT Devices:
# PGPLOT v5.2.2 Copyright 1997 California Institute of Technology
# Interactive devices:
#    /GW        (grwnd.exe on Win32)
#    /CGW       (grwnd.exe on Win32; colors compatible with /CPS)
# Non-interactive file formats:
#    /GIF       (Graphics Interchange Format file, landscape orientation)
#    /VGIF      (Graphics Interchange Format file, portrait orientation)
#    /NULL      (Null device, no output)
#    /PNG       (Portable Network Graphics file)
#    /TPNG      (Portable Network Graphics file - transparent background)
#    /PS        (PostScript file, landscape orientation)
#    /VPS       (PostScript file, portrait orientation)
#    /CPS       (Colour PostScript file, landscape orientation)
#    /VCPS      (Colour PostScript file, portrait orientation)
dev ("/GW");
imag (sin(rvals(200,200)+1));


  • $var(a:b,c:d…) to specify multidimensional slices
  • You can access ranges using the usual : separated format: $a($start:$stop:$step) *= 4;
  • Just as with slice negative indices count from the end of the dimension backwards with -1 being the last element. If the start index is larger than the stop index the resulting piddle will have the elements in reverse order between these limits
  • As in slice, you can insert a dummy dimension by preceding a single index argument with '*'. A lone '*' inserts a dummy dimension of order 1; a '*' followed by a number inserts a dummy dimension of that order.
  • You can use piddles to specify indices in ranges. No need to turn them into proper perl scalars with the new slicing syntax. However, make sure they contain not more than one element!
  • An empty argument selects the whole dimension, in this example all of the first dimension: print $a(,(0));
  • Example
perldl> $a=sequence(10)
perldl> $b.=$a+10
perldl> p $a, $b
[0 1 2 3 4 5 6 7 8 9] [10 11 12 13 14 15 16 17 18 19]
perldl> $c=cat($a,$b)
perldl> p$c
 [ 0  1  2  3  4  5  6  7  8  9]
 [10 11 12 13 14 15 16 17 18 19]
perldl> p $c(0:-1,0)
 [0 1 2 3 4 5 6 7 8 9]
perldl> p $c(:,1)
 [10 11 12 13 14 15 16 17 18 19]
perldl> p $c(,0)
 [0 1 2 3 4 5 6 7 8 9]
perldl> p $c(,(1)) # Put dim in parens to remove degenerate
[10 11 12 13 14 15 16 17 18 19]


# Starting code
$a = sequence(5);
$b = pdl(1);
# Roll Left
$c = $a->range($b,[$a->dims],'p');
# Rotate Left
$c=$a->rotate(-1); # or
# Shift Left
$c = $a->range($b,[$a->dims],'t');
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License