Skip to content

Instantly share code, notes, and snippets.

@asimjalis
Created December 8, 2012 15:34
Show Gist options
  • Save asimjalis/4240761 to your computer and use it in GitHub Desktop.
Save asimjalis/4240761 to your computer and use it in GitHub Desktop.
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")
@MooM00
Copy link

MooM00 commented Dec 23, 2022

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.

Windows doesn't understand that ' is also a quote character; you must use " for quoting the inline script
Luckily in perl TIMTOWTDI, so use this in windows:
perl -e "do{print('perl> ');$_x=<>;chomp $_x;print(eval($_x).qq[\n])}while($_x ne 'q')"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment