PERLDL(1p)
PERLDL(1p) ๐ Simple shell for PDL
โจ NAME โจ
perldl - Simple shell for PDL ๐ซถ
โจ SYNOPSIS โจ
Use PDL interactively:
bash$ perldl
pdl> $x = sequence(10) # or any other perl or PDL command
bash$ pdl
pdl> print "Hello, world!\n";
pdl> with_time { print +($A->matmult($B))->info, "\n" } for 1..5;
pdl> gv $A, 'output.png' # uses GraphViz2 to show connected transforms etc
pdl> 1+1 # no output
pdl> do_print 1 # or put this in your .perldlrc - as of 2.099
pdl> 1+1; # no output, like MATLAB
pdl> 1+1
2
Run a script:
bash$ cat > pdlscript
#!/usr/bin/pdl
print "Hello, world!\n";
...
โจ DESCRIPTION โจ
Okay so perldl is a simple shell (written in perl) for interactive use of PDL. It's 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). Slay. ๐
The synonym pdl is a compiled executable that is useful as a script interpreter using UNIX shebang (#!) syntax. This is useful for generating and re-executing command-journal files from perldl. Periodt.
The perldl shell runs an initial startup file (~/.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. It's giving iconic. ๐
Depending on your configuration settings, 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.
perldl and pdl support several command-line options, which are discussed near the end of this document. Bestie, we'll get there. ๐
Reference manual & online help โจ
The PDL reference manual and online help are available from within perldl, using the help and apropos commands (which may also be abbreviated ? and ??.) The help command alone prints a summary of help syntax, and help <module-name> will print POD documentation from the module you mention (POD is the Perl format for embedding documentation in your perl code; see perlpod for details). ๐ฆ
If you include POD documentation in your autoload subroutines (see path mechanism below), then both help and apropos will find it and be able to format and display it on demand.
History mechanism โจ
If you have the perl modules ReadLines and ReadKeys installed, then perldl supports a history and line-editing mechanism using editing keys similar to emacs. The last 500 commands are always stored in the file .perldl_hist in your home directory between sessions. Set $PERLDL::HISTFILESIZE to change the number of lines saved. The command l [number] shows you the last number commands you typed where number defaults to 20.
e.g.:
bash$ perldl
ReadLines enabled
pdl> $x = rfits "foo.fits"
BITPIX = -32 size = 88504 pixels
Reading 354016 bytes
BSCALE = && BZERO =
pdl> imag log($x+400)
Displaying 299 x 296 image from 4.6939525604248 to 9.67116928100586 ...
Command execution โจ
If you enter a simple command at the 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:
$_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.
- Scope is not preserved across lines ๐ซ
Each command line is executed in a separate eval block within perl, so scoping commands such as my and local may not perform exactly as expected -- in particular, if you declare a variable with my, it is local to the particular command line on which you typed the my command, which means that it will evaporate before the next prompt is printed. (You can use my variables in a multi-line block or to isolate values within a single command line, of course).
- 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 "Hello world" in Perl, but (under most circumstances) "Hello " in perldl.
- Multi-line execution ๐ง
In multiline mode (which is enabled by default, see Shell variables, below), perldl searches for searches for block-like constructs with curly braces, parentheses, quotes, and related delimiters. If you leave such a construct open, perldl accepts more lines of input until you close the construct or explicitly 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) perldl.
Warning: The multi-line parsing uses Damian Conway'sText::Balancedmodule, which contains some flaws -- so it can be fooled by quote-like operators such asq/.../, included POD documentation, multi-line<<quotes, and some particularly bizarre-but-validm/.../matches ands/.../.../substitutions. In such cases, use^Dto close out the multi-line construct and force compilation-and-execution.
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 pdl instead of perl as the interpreter in the script's initial shebang line.
Terminating "perldl" โจ
A perldl session can be terminated with any of the commands quit, exit or the shorthands x or 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 perldl.
Terminating commands (Ctrl-C handling) โจ
Commands executed within perldl can be terminated prematurely using Ctrl-C (or whichever key sequence sends an INT signal to the process on your terminal). Provided your PDL code does not ignore sigints this should throw you back at the perldl command prompt:
pdl> $result = start_lengthy_computation()
<Ctrl-C>
Ctrl-C detected
pdl>
As of 2.077, this requires Sys::SigAction to be installed (without that, and before 2.077, for Perl >5.8 it didn't actually interrupt things).
Shortcuts and aliases โจ
- The shell aliases
pto be a convenient short form ofprint, e.g.
pdl> p ones 5,3
[
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
]
qandxare short-hand forquit.llists the history buffer
pdl> l # list last 20 commands
pdl> l 40 # list last 40 commands
?is an alias for help
pdl> ? vars # show information about ndarrays in current namespace
??is an alias for apropos
pdl> ?? PDL::Doc
- help, apropos, usage and 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'
with_timeruns the following code-block, and tells you how long it took, in milliseconds. RequiresTime::HiRes.
pdl> with_time { print +($A->matmult($B))->info, "\n" } for 1..5;
gvusespdumpgraphinPDL::Coreetc to visualise the given ndarray, with all connected transformations, etc, into the given file. Requires Graph and GraphViz2.
pdl> gv $A, 'output.png'
Command-line options โจ
perldl and 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 pdl> prompt. They are:
-glutโ Load OpenGL when starting the shell (the perl OpenGL module, which is available from CPAN must be installed). This enables readline event loop processing. Don't use with-tk.-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. Don't use with-glut.-ffile โ Loads the file before processing any user input. Any errors during the execution of the file are fatal.-wโ Runs with warning messages (i.e. the normal perl-wwarnings) turned-on.-Mmodule โ Loads the module before processing any user input. Compare correspondingperlswitch.-mmodule โ Unloads the module before processing any user input.-Idirectory โ Adds directory to the include path. (i.e. the@INCarray) Compare correspondingperlswitch.-Vโ Prints a summary of PDL config. This information should be included with any PDL bug report. Compare correspondingperlswitch.
The startup file ~/.perldlrc โจ
If the file ~/.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 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 ~/.perldlrc. You may wish to start from the existing 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 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 specifically 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.
Shell variables โจ
Shell variables: (Note: if you don't like the defaults change them in ~/.perldlrc)
$PERLDL::ESCAPE- default value'#'- the escape character (the one from the list above, you know the vibe ๐ ) โ 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. iconic behavior honestly.
$PERLDL::HISTFILESIZEโ default value500. This is literally how many lines ofperldlshell command history get kept. that's it that's the whole job ๐ซถ$PERLDL::PAGERโ default value"more". This is the external program that filters the output of commands. Using"more"prints output one screenful at a time (so you don't get obliterated by a wall of numbers ๐ฅ). On Unix, settingpage(1)and$PERLDL::PAGERto"tee -a outfile"will keep a record of the output generated by subsequentperldlcommands (without paging). lowkey a diary of your data. โจ$PERLDL::PROMPTโ default value'pdl> '. Enough said ๐ But bestie, it 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. main character prompt energy fr.$PERLDL::MULTIโ default value1. If this is set to a true value, thenperldlwill 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. so helpful of it ๐
Note that this is not (yet!) a complete perl parser. In particular, Text::Balanced appears to be able to ignore quoting operatores like "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. slay.
$PERLDL::NO_EOFโ default value0/1onMSWin32. Protects against accidental use of"^D"from the terminal. If this is set to a true value, then you can't accidentally exitperldlby typing"^D". If you set it to a value larger than1(andPERLDL::MULTIis 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. safety rail ๐$HOMEโ the user's home directory. that's it. your house. ๐$PERLDL::TERMโ this is theTerm::ReadLineobject associated with theperldlshell. It can be used by routines called fromperldlif your command is interactive. fancy โจ$PDL::toolongtoprintโ the maximal size pdls to print (defaults to10,000elements). This is not just a"perldl"variable but it is something that is usually needed in an interactive debugging session. so real ๐ฅ
๐ธ Executing scripts from the 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'. hot reload who? no cap. ๐ฆ
๐ง 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. periodt. โจ
๐ฎ Command preprocessing ๐ฎ
NOTE: This feature is used by default by PDL::NiceSlice. See below for more about slicing at the "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). so thoughtful fr.
*NOTE*: The preprocessing interface has changed from earlier versions! The old way using $PERLDL::PREPROCESS will still work but is strongly deprecated and might go away in the future. โ ๏ธ bestie, migrate, im begging.
You can enable preprocessing by registering a filter with the "preproc_add" function. "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 "perldl" completely unusable if you fail to return the modified string; quitting is then your only option. ๐ญ genuinely. return the string. please.
Filters can be removed from the preprocessing pipeline by calling "preproc_del" with the filter to be removed as argument. To find out if a filter is currently installed in the preprocessing pipeline use "preproc_registered":
pdl> preproc_add $myfilter unless preproc_registered $myfilter;
Previous versions of "perldl" used the variable $PERLDL::PREPROCESS. This will still work but should be avoided. Please change your scripts to use the "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. iykyk. ๐
You can remove this preprocessor using the "preproc_del" function which takes one argument (the filter to be removed, it must be the same coderef that was returned from a previous "preproc_add" call):
pdl> preproc_del $filter;
An example of actual usage can be found in the "perldl" script. Look at the function "trans" to see how the niceslicing preprocessor is enabled/disabled. โจ
๐ "perldl" and PDL::NiceSlice ๐
PDL::NiceSlice introduces a more convenient slicing syntax for ndarrays. In the current version of "perldl" niceslicing is enabled by default (if the required CPAN modules are installed on your machine). ๐
At startup "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 "NiceSlice" is enabled you can use the enhanced slicing syntax:
pdl> $x = sequence 10;
pdl> p $x(3:8:2)
For details consult 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 "perldl" shell to switch this preprocessing on or off and also explicitly check the substitutions that the NiceSlice filter makes. very demure, very mindful. ๐
You can switch the 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 $x(3:8:2)
processed p $x->slice([3,8,2])
[3 5 7]
Similarly, switch reporting off as needed
pdl> report 0;
pdl> p $x(3:8:2)
[3 5 7]
Reporting is off by default. lowkey spying on your own code ๐ฅ
๐ 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. obsessed. ๐
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 "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! โ ๏ธ bestie, with great power etc etc. you know the vibe. ๐
and that's the whole page, bestie โ this one came from perl v5.42.3, dated 2026-08-20, filed under PERLDL(1p). go forth and slice responsibly ๐๐
๐ฆ where this page comes from
- ubuntu stonking: pdl 1:2.106-1build1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms