Random Geekery

REPL In Perl With Reply

Added by to Tools on

Tags · perl · reply ·

Connect To MongoDB on a Vagrant box from the host .replyrc And reply -Mojo
Perl Reply Screenshot
Perl Reply Screenshot

Time for a quick post about Reply, a new Perl toy from Jesse Luers. There will not be much for me to say, because I have only been playing with it for about twenty minutes.

Reply is a REPL for Perl. It is an interactive shell that simplifies quick experimentation with language features. It is extensible via a plugin system that I may look at later if I have more time.


I use perlbrew and cpanm, so installation was easy.

$ cpanm Reply

Oh. It is worth pointing out that if you do not have GNU Readline or a similar library installed, you will not get command-line editing or history in Reply.

Hello Reply

The reply command starts a new session. Once the session is going, it’s pretty much just Perl.

$ reply
0> "Hello World"
$res[0] = 'Hello World'

1> my $name = "Brian"
$res[1] = 'Brian'

2> "Hello $name"
$res[2] = 'Hello Brian'

Getting user input via STDIN works pretty much how you would expect.

3> chomp( $name = <STDIN> )
$res[3] = 1

4> $name
$res[4] = 'Brian'

Defining subroutines is no big deal.

5> sub greeting { "Hello $_[0]" }
6> greeting $name
$res[5] = 'Hello Brian'

And exit will quit Reply. It all seems straightforward.

7> exit

A Marginally More Complex Example

I have been working on a little experiment: fetching Questhub.io JSON with Mojo::UserAgent and Mojo::JSON. I decided to see if I could try some of that experiment in Reply.

0> use Mojo::UserAgent
1> use Mojo::JSON 'decode_json'
2> my $ua = Mojo::UserAgent->new
$res[0] = bless( {}, 'Mojo::UserAgent' )

3> sort map { $_->{name} } @{ decode_json( $ua->get( 'https://questhub.io/api/realm' )->res->body ) }
$res[1] = [
  'Big Data',
  'DC Metro Region',
  'Python (Ru)',
  'Yoga + Meditation'

Yes, I can.

What Do I Think?

I like Reply overall. I am not used to thinking in REPL terms when it comes to Perl, and need to spend more than twenty minutes with it. I like Reply enough that I do expect to spend more time with it.

I noticed that my coding style was more terse within the confines of Reply. Maybe I should install GNU Readline support on my machine or enable the Editor plugin.