Repository navigation
Perl workspace
Immediate input and RUN evaluate real Perl in a shared package. Line
numbers organize source; they do not turn Perl into BASIC or create GOTO
targets.
For immediate function/container definitions and implicit word lists, see
shortcuts and shorthand. Literal EVAL and stored
programs always retain ordinary Perl syntax. Shorthand is direct:
E s triple return 3 * shift or a one, two. E reserves the five definition
tags; EVAL always takes literal Perl. Native quotes work inside shorthand lists.
Replacing a shorthand destination asks first; E! s ... or a! ...
skips that confirmation. Literal Perl retains its normal redefinition behavior.
After a function is defined, use Perl's normal call syntax:
EVAL sub triple { 3 * shift }
say triple 14
42
Prototypes still control Perl's parsing. For example:
EVAL sub scalar_arg ($) { 3 * $_[0] }
say scalar_arg 14
42
EVAL sub total (@) { my $n = 0; $n += $_ for @_; $n }
say total 1, 2, 3
6
EVAL sub apply (&@) { my $f = shift; map { $f->($_) } @_ }
say join q{,}, apply { $_[0] * 2 } 1, 2, 3
2,4,6
The parentheses in prototype declarations and code-reference calls are
intentional. Keep parentheses where required or useful for grouping arguments.
AnteREPL does not rewrite call syntax. Define or import the function first;
prototypes installed by RUN are available to later immediate calls too.
$count = 3;
say $count;The second line prints 3. Package scalars, arrays, hashes, and subroutines
survive between evaluations. our $count = 3 also works.
By contrast, my $count = 3 belongs to that one evaluation. A separate input
line is a separate evaluation and cannot see the lexical. All source in one
RUN is evaluated together, so my variables work normally across its lines:
10 my $total = 6 * 7
20 say $total
RUNThis prints 42. say is enabled by default. Strict subs and refs are on;
strict vars is off so workspace variables can be used without declarations.
Pragmas and lexical imports are local to the evaluation in which they occur.
Enter:
$FOO = {
bar => 1,
names => [qw(Alice Bob)],
};Open delimiters continue onto another row. Closing the structure and pressing Enter evaluates the complete entry. The screen retains the rows as a group; editing a row in that group and submitting it evaluates the whole group again.
Continuation is a delimiter check, not a full Perl parser. For heredocs, POD,
or syntax it cannot recognize reliably, use EDIT or exact numbered source.
In AUTO, completed multiline entries are stored instead of executed and retain
their own semicolons. See AUTO entry.
With AUTO off, type or paste a do { ... } entry. To keep AUTO active, prefix
the entry with EVAL:
EVAL do {
my $total = 0;
for my $n (1 .. 3) {
$total += $n;
}
if ($total > 0) {
say $total;
}
};This prints 6 and leaves the stored program untouched. The enclosing block
keeps line-by-line typing in one evaluation and lets its statements share
lexicals. Bracketed paste also groups the pasted text and waits for Enter.
The terminal must support bracketed paste; the outer do block also works
when pasting through a terminal that sends ordinary lines.
Shift+Enter inserts a newline at the cursor without submitting the entry when your terminal reports it distinctly; Ctrl-N performs the same edit. Move up, split or edit rows, close the braces, then press Enter to run the complete group. See screen keys for terminal compatibility.
The AnteREPL command must be uppercase EVAL. Lowercase eval remains Perl's
keyword, including exception catching and string evaluation:
eval { die "example\n" }; say "Caught: $@";
eval 'say "string eval"';Use $@ in the same submitted entry, since the next REPL evaluation can change
it. During AUTO, lowercase eval is stored like other Perl source; uppercase
EVAL explicitly executes immediately. All other REPL commands and subcommands must also be uppercase.
10 sub twice { return 2 * shift }
RUN
say twice 21
This prints 42. RUN evaluates the stored source and defines its named
subroutines in the same workspace as immediate input. It also executes every
other top-level statement in the program. Merely storing or loading a
definition does not make it callable; run it first. During AUTO, use
EVAL say twice 21 for an immediate call.
You can also define a multiline subroutine directly with AUTO off:
sub plus_one {
return 1 + shift;
}
say plus_one(41)That definition persists in the workspace without becoming stored source.
Use LIST or EDIT to revisit a definition that is in the stored program.
Editing or deleting stored source does not alter the live function immediately;
redefine it with another RUN, or use RESET to select a fresh workspace.
Define a named function directly in the current REPL workspace's symbol table:
AUTO OFF
EVAL sub triple {
return 3 * shift;
}
say triple 14
Press ordinary Enter after }. The definition produces no output; the next
entry calls it and prints 42. EVAL also works during AUTO, but does not turn
AUTO off. Use ? triple 14 to call it immediately while AUTO remains active.
A prototype works the same way: E sub twice ($) { 2 * $_[0] } completes
with one Enter, and the next entry, say twice 21, prints 42. An open body
continues until its closing brace. Ctrl-C cancels an unfinished entry;
commands such as CLS typed inside it are still part of the Perl text.
The function lives in this Perl process and is callable from immediate code
and RUN. Its definition does not enter the numbered program, LIST, or SAVE.
Here "session-only" means a normal named subroutine in the workspace package,
not Perl's local keyword or a lexical my sub.
CLS and NEW/CLEAR retain live functions. RESET selects a fresh workspace where the function is no longer defined. Saving a program that calls a session-only function does not save that function's definition with it.
If you deliberately want a definition in a saved program, enter its source through numbered lines, AUTO, or EDIT and then SAVE. The experimental STORE command and pending EVAL source buffer have been removed; evaluating a function never automatically copies its source into the program.
Type FUNCTIONS to list defined function names in the current
workspace, one per line in alphabetical order:
FUNCTIONS
triple
This reads the live symbol table. It includes imported functions and aliases
in the workspace, and functions installed by RUN. It excludes other packages,
forward declarations without a body, and anonymous functions held only in
variables. Stored definitions do not appear until you run them. The command
takes no arguments and also works during AUTO without storing or running source.
An empty workspace reports No functions defined in this workspace. After
RESET, the list starts empty even when the numbered program is retained.
LIST continues to show the numbered source; FUNCTIONS shows live names.
Defining a named subroutine again through ordinary Perl replaces the function
used by subsequent calls and prints Perl's usual warning. There is no confirmation
for literal Perl; shorthand redefinitions ask first (E! s ... skips
that question):
EVAL sub triple { return 4 * shift; }
Subroutine triple redefined at PERL_ANTE_REPL_prompt line 1.
EVAL say triple 14
56
An existing code reference, such as $old = \&triple, still calls the previous
body. A later \&triple gets the replacement. Normal Perl warning controls
apply, including no warnings 'redefine' within the submitted entry.
Code outside the sub body runs once each time you submit the entry:
EVAL do {
$setups++;
sub twice { return 2 * shift; }
say "Setup $setups";
}
EVAL say twice 21
The first entry prints Setup 1; the second prints 42 without rerunning the
setup. Named subroutines are installed at compile time. Evaluation is not
transactional: a later runtime exception does not undo their definitions or
other side effects already performed.
DUMP $FOO
DUMP \%ENV
? $FOO->{names}[0]
PEEK $FOO
PEEK $FOO, 10DUMP calls Data::Dumper::Dumper. References let it display whole arrays
and hashes. ? expression evaluates in scalar context and uses a terse Dumper
display. Ordinary expression input does not print its return value.
PEEK calls the core module Devel::Peek, showing scalar types, flags,
reference counts, and referenced values. The optional number limits traversal.
It operates directly on the expression, rather than a copied result.
DUMP and PEEK are AnteREPL commands, not added keywords inside stored programs. In stored source, call the module functions explicitly:
10 use Data::Dumper ()
20 print Data::Dumper::Dumper($FOO)AnteREPL recognizes commands and leading editing numbers first. Use an escape when you specifically want Perl:
? 10 + 20
EVAL 10 + 20
EVAL say "RUN is just text here";? displays the result; EVAL does not automatically display it. During AUTO,
EVAL is also how you execute a line immediately without storing it.
| Command | Source program | Package variables/functions | %ENV |
|---|---|---|---|
RUN |
Retained | Shared and possibly changed by source | Shared |
CLS |
Retained | Retained | Retained |
NEW / CLEAR
|
Cleared after unsaved-source check | Retained | Retained |
RESET |
Retained | Switch to a fresh workspace | Retained |
ENV RESET |
Retained | Retained | Restore startup environment |
UNDO |
Restore previous source edit | No rollback | No rollback |
Source files do not save live values. Initialize needed values in the source
before expecting an exported script to run on its own. Exceptions and Ctrl-C
do not undo side effects already performed by Perl. Perl's exit exits the app.
For normal screen output, use say, print, and warn. Simple <STDIN> line
input also works. Direct system/exec calls and arbitrary native XS output
can bypass the screen model; use !, !!, and PEEK for those operations.