/usr/lib/perl5/PDL/perldl.pod is in pdl 1:2.4.7+dfsg-2ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | =head1 NAME
perldl - Simple shell for PDL (also see pdl2)
=head1 SYNOPSIS
Use PDL interactively:
bash$ perldl
pdl> $a = sequence(10) # or any other perl or PDL command
bash$ pdl
pdl> print "Hello, world!\n";
Run a script:
bash$ cat > pdlscript
#!/usr/bin/pdl
print "Hello, world!\n";
...
=head1 DESCRIPTION
The program B<perldl> is a simple shell (written in perl) for
interactive use of PDL. It consists of a command-line interface that
supports immediate interpretation of perl commands and expressions.
Perl expressions, including PDL constructs, can be entered directly at
the keyboard and are compiled and executed immediately. The syntax is
not exactly identical to Perl, in that under most circumstances ending
a line causes immediate execution of the command entered so far (no
trailing ';' is required).
The synonym B<pdl> is a compiled executable that is useful as a script
interpreter using UNIX shebang (C<#!>) syntax. This is useful for generating
and re-executing command-journal files from B<perldl>.
The B<perldl> shell runs an initial startup file (C<~/.perldlrc>) that can
be used to pre-load perl modules or configure the global perl environment. It
features a path mechanism for autoloading perl subroutines. There is a
command-history mechanism, and several other useful features such as command
preprocessing, shortcuts for commonly used commands such as "print",
and the ability to execute arbitrary code whenever a prompt is printed.
Depending on your configuration settings, B<perldl> can be set to
honor or ignore the ^D (end-of-file) character when sent from a
terminal, or to attempt to do the Right Thing when a block construct
spanning multiple lines is encountered.
B<perldl> and B<pdl> support several command-line options, which are
discussed near the end of this document.
=head2 Reference manual & online help
The PDL reference manual and online help are available from within
B<perldl>, using the B<help> and B<apropos> commands (which may also
be abbreviated B<?> and B<??>.) The B<help> command alone prints a summary of
help syntax, and B<help E<lt>module-nameE<gt>> will print POD documentation
from the module you mention (POD is the Perl format for embedding
documentation in your perl code; see L<perlpod> for details).
If you include POD documentation in your autoload subroutines (see
B<path mechanism> below), then both B<help> and B<apropos> will find it
and be able to format and display it on demand.
=head2 History mechanism
If you have the perl modules ReadLines and ReadKeys installed, then
B<perldl> supports a history and line-editing mechanism using editing
keys similar to L<emacs(1)>. The last 50 commands are always stored in
the file F<.perldl_hist> in your home directory between sessions.
Set C<$PERLDL::HISTFILESIZE> to change the number of lines saved.
The command C<l [number]> shows you the last C<number> commands you
typed where C<number> defaults to 20.
e.g.:
bash$ perldl
ReadLines enabled
pdl> $a = rfits "foo.fits"
BITPIX = -32 size = 88504 pixels
Reading 354016 bytes
BSCALE = && BZERO =
pdl> imag log($a+400)
Displaying 299 x 296 image from 4.6939525604248 to 9.67116928100586 ...
=head2 Command execution
If you enter a simple command at the B<perldl> command line, it is
immediately executed in a Perl eval(). The environment is almost identical
to that within a perl script, with some important exceptions:
=over 3
=item * $_ is not preserved across lines
$_ is used to hold the command line for initial processing, so at the
beginning of processing of each command line, $_ contains the command itself.
Use variables other than $_ to store values across lines.
=item * Scope is not preserved across lines
Each command line is executed in a separate C<eval> block within perl,
so scoping commands such as C<my> and C<local> may not perform exactly
as expected -- in particular, if you declare a variable with C<my>, it
is local to the particular command line on which you typed the C<my>
command, which means that it will evaporate before the next prompt is printed.
(You can use C<my> variables in a multi-line block or to isolate values within
a single command line, of course).
=item * Execution is immediate
Under most circumstances, as soon as you end a line of input the line
is parsed and executed. This breaks Perl's normal dependence on
semicolons as command delimiters. For example, the two-line expression
print "Hello ",
"world";
prints the phrase C<Hello world> in Perl, but (under most circumstances)
C<Hello > in B<perldl>.
=item * Multi-line execution
In multiline mode (which is enabled by default, see B<Shell
variables>, below), B<perldl> searches for searches for block-like
constructs with curly braces, parentheses, quotes, and related
delimiters. If you leave such a construct open, B<perldl> accepts more
lines of input until you close the construct or explictly end the multi-line
expression with ^D. Following the example above, the phrase
{ print "Hello ",
"world"; }
will print "Hello world" from either Perl or (in multi-line mode)
B<perldl>.
B<Warning>: The multi-line parsing uses Damian Conway's
L<Text::Balanced> module, which contains some flaws -- so it can be
fooled by quote-like operators such as C<q/.../>, included POD
documentation, multi-line C<E<lt>E<lt>> quotes, and some
particularly bizarre-but-valid C<m/.../> matches and C<s/.../.../>
substitutions. In such cases, use ^D to close out the multi-line construct and
force compilation-and-execution.
=back
If you want to preserve this behavior in a script (for example to replay a command
journal file; see below on how to create one), you can use B<pdl> instead of B<perl>
as the interpreter in the script's initial shebang line.
=head2 Terminating C<perldl>
A C<perldl> session can be terminated with any of the commands
C<quit>, C<exit> or the shorthands C<x> or C<q>. If EOF handling is
switched on (the default) you can also type ^D at the command prompt.
If the command input is NOT a terminal (for example if you are running
from a command journal file), then EOF will always terminate B<perldl>.
=head2 Terminating commands (Ctrl-C handling)
Commands executed within C<perldl> can be terminated prematurely
using C<Ctrl-C> (or whichever key sequence sends an INT signal
to the process on your terminal). Provided your PDL code does not
ignore C<sigint>s this should throw you back at the C<perldl>
command prompt:
pdl> $result = start_lengthy_computation()
<Ctrl-C>
Ctrl-C detected
pdl>
=head2 Shortcuts and aliases
=over
=item *
The shell aliases C<p> to be a convenient short form of C<print>, e.g.
pdl> p ones 5,3
[
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
]
=item *
C<q> and C<x> are short-hand for C<quit>.
=item *
C<l> lists the history buffer
pdl> l # list last 20 commands
pdl> l 40 # list last 40 commands
=item *
C<?> is an alias for L<help|PDL::Doc::Perldl/help>
pdl> ? pdl2 # get help for new pdl2 shell
=item *
C<??> is an alias for L<apropos|PDL::Doc::Perldl/apropos>
pdl> ?? PDL::Doc
=item *
L<help|PDL::Doc::Perldl/help>, L<apropos|PDL::Doc::Perldl/apropos>,
L<usage|PDL::Doc::Perldl/usage> and L<sig|PDL::Doc::Perldl/sig>:
all words after these commands are used verbatim and not evaluated
by perl. So you can write, e.g.,
pdl> help help
instead of
pdl> help 'help'
=back
=head2 Command-line options
B<perldl> and B<pdl> support several command-line options to adjust the behavior of the
session. Most of them are equivalent to commands that can be entered at the B<perldlE<gt>>
prompt. They are:
=over 4
=item -tk
Load Tk when starting the shell (the perl Tk module, which is
available from CPAN must be installed). This enables readline
event loop processing.
=item -f file
Loads the file before processing any user input. Any errors
during the execution of the file are fatal.
=item -w
Runs with warning messages (i.e. the normal perl C<-w> warnings)
turned-on.
=item -M module
Loads the module before processing any user input.
Compare corresponding C<perl> switch.
=item -m module
Unloads the module before processing any user input.
=item -I directory
Adds directory to the include path. (i.e. the @INC array)
Compare corresponding C<perl> switch.
=item -V
Prints a summary of PDL config. This information should
be included with any PDL bug report. Compare corresponding
C<perl> switch.
=back
=head2 The startup file F<~/.perldlrc>
If the file F<~/.perldlrc> is found it is sourced at start-up to load default
modules, set shell variables, etc. If it is NOT found the distribution file
F<PDL/default.perldlrc> is read instead. This loads various modules
considered useful by default, and which ensure compatibility with
v1.11. If you don't like this and want a more streamlined set of your
own favourite modules simple create your own F<~/.perldlrc>. You may
wish to start from the existing F<PDL/default.perldlrc> as a template
since it will not be sourced once you replace it with your own version.
To set even more local defaults the file F<local.perldlrc> (in the current
directory) is sourced if found. This lets you load modules and define
subroutines for the project in the current directory.
The name is chosen specfically because it was found hidden files were
NOT wanted in these circumstances.
The startup file should normally include "use PDL::AutoLoader;", as
many of the nicer interactive features won't work without it.
=head2 Shell variables
Shell variables: (I<Note>: if you don't like the defaults change
them in F<~/.perldlrc>)
=over
=item *
$PERLDL::ESCAPE - default value '#'
Any line starting with this character is treated as a shell
escape. The default value is chosen because it escapes the
code from the standard perl interpreter.
=item *
$PERLDL::HISTFILESIZE - default value 500
This is the number of lines of perldl shell command history
to keep.
=item *
$PERLDL::PAGER - default value C<more>
External program to filter the output of commands. Using C<more>
prints output one screenful at a time. On Unix, setting C<page(1)>
and $PERLDL::PAGER to C<tee -a outfile> will keep a record of the
output generated by subsequent perldl commands (without paging).
=item *
$PERLDL::PROMPT - default value 'perldl> '
Enough said But can also be set to a subroutine reference, e.g.
$PERLDL::PROMPT = sub {join(':',(gmtime)[2,1,0]).'> '} puts the
current time into the prompt.
=item *
$PERLDL::MULTI - default value 1
If this is set to a true value, then perldl will parse multi-line
perl blocks: your input will not be executed until you finish a line
with no outstanding group operators (such as quotes, blocks, parenthesis, or
brackets) still active. Continuation lines have a different prompt that
shows you what delimiters are still active.
Note that this is not (yet!) a complete perl parser. In particular,
Text::Balanced appears to be able to ignore quoting operatores
like C<q/ ... /> within a line, but not to be able to extend them across
lines. Likewise, there is no support for the '<<' operator.
Multiline conventional strings and {}, [], and () groupings are well
supported.
=item *
$PERLDL::NO_EOF - default value 0 / 1 on MSWin32
Protects against accidental use of "^D" from the terminal. If this is
set to a true value, then you can't accidentally exit perldl by typing
"^D". If you set it to a value larger than 1 (and PERLDL::MULTI is
set), then you can't use "^D" to exit multiline commands either. If
you're piping commands in from a file or pipe, this variable has no
effect.
=item *
$HOME
The user's home directory
=item *
$PERLDL::TERM
This is the Term::ReadLine object associated with the perldl
shell. It can be used by routines called from perldl if your
command is interactive.
=back
=head2 Executing scripts from the C<perldl> prompt
A useful idiom for developing perldl scripts or editing functions
on-line is
pdl> # emacs script &
-- add perldl code to script and save the file
pdl> do 'script'
-- substitute your favourite window-based editor for 'emacs' (you may
also need to change the '&' on non-Unix systems).
Running "do 'script'" again updates any variables and function
definitions from the current version of 'script'.
=head2 Executing perldl scripts from the command line
PDL scripts are just perl scripts that happen to use PDL (and
possibly PDL::NiceSlice). But for the truly lazy, perldl can be
invokes as a script interpreter. Because perldl is itself an interpreted
perl script, most unices won't allow you to say "#!/usr/bin/perldl"
at the top of your script.
Instead, say "#!/usr/bin/pdl" and your script will be executed exactly
as if you typed it, line-by-line, into the perldl shell.
=head2 Command preprocessing
NOTE: This feature is used by default by L<PDL::NiceSlice|PDL::NiceSlice>.
See below for more about slicing at the C<perldl> prompt
In some cases, it is convenient to process commands before they are
sent to perl for execution. For example, this is the case where the
shell is being presented to people unfamiliar with perl but who wish
to take advantage of commands added locally (eg by automatically
quoting arguments to certain commands).
*I<NOTE>*: The preprocessing interface has changed from earlier
versions! The old way using C<$PERLDL::PREPROCESS> will still
work but is strongly deprecated and might go away in the future.
You can enable preprocessing by registering a filter with the
C<preproc_add> function. C<preproc_add> takes one argument which
is the filter to be installed. A filter is a Perl code reference (usually
set in a local configuration file) that will be called, with the
current command string as argument, just prior to the string being
executed by the shell. The modified string should be returned. Note
that you can make C<perldl> completely unusable if you fail to
return the modified string; quitting is then your only option.
Filters can be removed from the preprocessing pipeline by calling
C<preproc_del> with the filter to be removed as argument. To find out
if a filter is currently installed in the preprocessing pipeline use
C<preproc_registered>:
pdl> preproc_add $myfilter unless preproc_registered $myfilter;
Previous versions of C<perldl> used the variable C<$PERLDL::PREPROCESS>.
This will still work but should be avoided. Please change your scripts
to use the C<preproc_add> etc functions.
The following code would check for a call to function 'mysub'
and bracket arguments with qw.
$filter = preproc_add sub {
my $str = shift;
$str =~ s/^\s+//; # Strip leading space
if ($str =~ /^mysub/) {
my ($command, $arguments) = split(/\s+/,$str, 2);
$str = "$command qw( $arguments )"
if (defined $arguments && $arguments !~ /^qw/);
};
# Return the input string, modified as required
return $str;
};
This would convert:
pdl> mysub arg1 arg2
to
pdl> mysub qw( arg1 arg2 )
which Perl will understand as a list. Obviously, a little more effort
is required to check for cases where the caller has supplied a normal
list (and so does not require automatic quoting) or variable
interpolation is required.
You can remove this preprocessor using the C<preproc_del> function
which takes one argument (the filter to be removed, it must be the
same coderef that was returned from a previous C<preproc_add> call):
pdl> preproc_del $filter;
An example of actual usage can be found in the C<perldl> script. Look
at the function C<trans> to see how the niceslicing preprocessor is
enabled/disabled.
=head2 C<perldl> and L<PDL::NiceSlice|PDL::NiceSlice>
L<PDL::NiceSlice|PDL::NiceSlice> introduces a more convenient
slicing syntax for piddles. In current versions of C<perldl>
niceslicing is enabled by default (if the required CPAN modules
are installed on your machine).
At startup C<perldl> will let you
know if niceslicing is enabled. The startup message will contain
info to this end, something like this:
perlDL shell v1.XX
PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file
'COPYING' in the PDL distribution. This is free software and you
are welcome to redistribute it under certain conditions, see
the same file for details.
ReadLines, NiceSlice enabled
Reading /home/csoelle/.perldlrc...
Type 'demo' for online demos
Loaded PDL v2.XX
When you get such a message that indicates C<NiceSlice> is enabled
you can use the enhanced slicing syntax:
pdl> $a = sequence 10;
pdl> p $a(3:8:2)
For details consult L<PDL::NiceSlice>.
L<PDL::NiceSlice|PDL::NiceSlice> installs a filter in the
preprocessing pipeline (see above) to enable the enhanced slicing
syntax. You can use a few commands in the C<perldl> shell to
switch this preprocessing on or off and also explicitly check
the substitutions that the NiceSlice filter makes.
You can switch the L<PDL::NiceSlice|PDL::NiceSlice> filter on and off
by typing
pdl> trans # switch niceslicing on
and
pdl> notrans # switch niceslicing off
respectively. The filter is on by default.
To see how your commands are translated
switch reporting on:
pdl> report 1;
pdl> p $a(3:8:2)
processed p $a->nslice([3,8,2])
[3 5 7]
Similarly, switch reporting off as needed
pdl> report 0;
pdl> p $a(3:8:2)
[3 5 7]
Reporting is off by default.
=head2 Automatically execute your own hooks
The variable @PERLDL::AUTO is a simple list of perl code strings
and/or code reference. It is used to define code to be
executed automatically every time the user enters a new line.
A simple example would be to print the time of each command:
pdl> push @PERLDL::AUTO,'print scalar(gmtime),"\n"'
pdl> print zeroes(3,3)
Sun May 3 04:49:05 1998
[
[0 0 0]
[0 0 0]
[0 0 0]
]
pdl> print "Boo"
Sun May 3 04:49:18 1998
Boo
pdl>
Or to make sure any changes in the file 'local.perldlrc' are
always picked up :-
pdl> push @PERLDL::AUTO,"do 'local.perldlrc'"
This code can of course be put *in* 'local.perldlrc', but
be careful :-) [Hint: add C<unless ($started++)> to above
to ensure it only gets done once!]
Another example application is as a hook for Autoloaders
(e.g. PDL::AutoLoader) to add code too which allows them to
automatically re-scan their files for changes. This is
extremely convenient at the interactive command line. Since
this hook is only in the shell it imposes no inefficiency on
PDL scripts.
Finally note this is a very powerful facility - which means
it should be used with caution!
|