A first session#

Values#

Type an expression and its value is shown, written the way you would write it in Perl:

ipps> 2 ** 10
1024
ipps> "total: " . 4
'total: 4'
ipps> 1 == 1
true
ipps> undef
undef
ipps> { name => "ada", langs => ["perl", "rust"] }
{ langs => ['perl', 'rust'], name => 'ada' }

A number is bare and a string is in quotes, so you can tell 12 from '12'. A string gets the quotes that need the fewest escapes:

ipps> "it's"
q{it's}
ipps> "a\tb"
"a\tb"

A line is evaluated in list context, and a list of several values is shown in parentheses. A hash is a list of its keys and values:

ipps> my %age = (ada => 36, alan => 41)
('ada', 36, 'alan', 41)
ipps> localtime
(59, 47, 10, 13, 9, 126, 2, 285, 1)

Large values are cut, with a note of what was left out. The :dump command of the next chapter shows them whole.

ipps> [1 .. 40]
[
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  21, 22, 23, 24, ... (16 more)
]

Staying quiet#

Every Perl statement has a value, and you do not always want to see it. End the line with a semicolon and nothing is shown:

ipps> my $n = 12;
ipps> $n * 2
24

Three kinds of line show nothing even without the semicolon: a definition (sub, use, package), a loop or conditional typed by itself, and a line whose last statement is print, printf or say, whose value would only be whether the output worked.

ipps> for my $p (2, 3) { print "$p squared is ", $p ** 2, "\n" }
2 squared is 4
3 squared is 9

When your code prints something that does not end in a newline, the prompt still starts on a line of its own, and a % in reverse video marks the place where the output stopped:

ipps> print "no newline"
no newline%
ipps>

The % is not part of the output. It tells you that the newline you see was not printed by your code.

The last value#

The value last shown is in $ans, and when there were several, all of them are in @ans:

ipps> $n * 2
24
ipps> $ans + 1
25
ipps> map { $_ * $_ } 2, 3, 5, 7
(4, 9, 25, 49)
ipps> scalar @ans
4

More than one line#

Input that is not finished gets a second prompt until it is. An open bracket, an open quote, a here-document without its end and an expression that expects more all count:

ipps> for my $p (2, 3, 5, 7) {
 ...>     print "$p squared is ", $p ** 2, "\n";
 ...> }
2 squared is 4
3 squared is 9
5 squared is 25
7 squared is 49
ipps> 1 +
 ...> 2
3

Blank lines inside are kept, so pasted code works. To give up on unfinished input, press Ctrl-C.

Errors#

An error is printed and the session goes on with everything it had. The place is given as the line’s number at the prompt and the line within what you typed:

ipps> die "something went wrong\n"
something went wrong
ipps> $n
12
ipps> $undeclared_typo + 1
Use of uninitialized value $undeclared_typo in addition (+) at (ipps:14) line 1.
1

The session starts with warnings on and with strict for references and barewords, but not for variables: an undeclared $x works at a prompt. If you want all of strict, say so, and it holds from then on:

ipps> use strict;
ipps> $another_typo = 1
Global symbol "$another_typo" requires explicit package name (did you forget to declare "my $another_typo"?) at (ipps:16) line 1.

Keys#

Tab

Completes the word in front of the cursor: a variable, a key of a hash, a method after ->, a sub, a module after use, a file name inside a string, a command. With several candidates it completes as far as they agree; a second Tab lists them. When nothing of Perl fits the word, Tab completes a file name.

Up and Down

Walk through the lines entered before, including those of earlier sessions. Ctrl-R searches them.

Ctrl-C

At the prompt, drops what you have typed. While a line runs, stops that line. The session goes on either way.

Ctrl-D

On an empty prompt, ends the session. So do exit and :quit.

Tab knows the session. With a %colour and an object in $dog:

ipps> $col<Tab>
ipps> $colour{<Tab><Tab>
green}  red}
ipps> $dog-><Tab><Tab>
DOES      can       import    name      speak
VERSION   fetch     isa       new       unimport

It reads what exists and runs nothing, so it cannot complete through the result of a call.