Collecting my attempts to improve at tech, art, and life

REPL In Perl With Reply

Tags: perl reply mojolicious tools

Series: [The Reply Perl REPL]

attachments/img/2014/cover-2014-08-14.png

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.

NOTE

This post used Questhub.io for a subject. Unfortunately, that site is no longer with us.

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.

Installation

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> )
Brian
$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',
  'Chaos',
  'Code',
  'DC Metro Region',
  'Fitness',
  'Haskell',
  'Japanese',
  'Lisp',
  'MOOCs',
  'Meta',
  'Node.js',
  'Perl',
  'Portland',
  'Python (Ru)',
  'Read',
  'Testing',
  '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.


Got a comment? A question? More of a comment than a question?

Talk to me about this page on:

Added to vault 2024-01-15. Updated on 2024-02-01