Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to run Perl in an interactive shell

How to run Perl in an interactive shell

by Asim Jalis, MetaProse.com

An interactive shell is useful for quickly trying out different commands. While Ruby, Python, and Clojure come with interactive shells, Perl does not. However, it is easy to create one using this one-liner on Unix systems:

perl -e 'do{print("perl> ");$_x=<>;chomp $_x;print(eval($_x)."\n")}while($_x ne "q")'

To quit type q.

To make this easier to remember save the following text in a file called perli:

#!/usr/bin/env perl
do{print("perl> ");$_x=<>;chomp $_x;print(eval($_x)."\n")}while($_x ne "q")
@f3l1x

This comment has been minimized.

Copy link

commented Feb 12, 2016

In Windows 10 x64 with ActivePerl it does not work, any idea how to solve it? Thank you.

@xiaottang2

This comment has been minimized.

Copy link

commented Aug 26, 2016

that's fun! especially it does everything in one line of code

@chuanqinggao

This comment has been minimized.

Copy link

commented Dec 12, 2016

perl -de1 works well on Windows.

@jasper-zanjani

This comment has been minimized.

Copy link

commented Apr 16, 2019

so the interactive shell wasn't available before Perl6?

@msegzda

This comment has been minimized.

Copy link

commented Jun 21, 2019

In Windows 10 x64 with ActivePerl it does not work, any idea how to solve it? Thank you.

Same here:

perl -e 'do{print("perl> ");$_x=<>;chomp $_x;print(eval($_x)."\n")}while($_x ne "q")'
> was unexpected at this time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.