<p>How can I start an interactive console for Perl, similar to the <code>irb</code> command for Ruby or <code>python</code> for Python?</p>

[{'answer_id': 73685, 'author': 'Brian Phillips', 'author_id': 7230, 'author_profile': 'https://Stackoverflow.com/users/7230', 'pm_score': 3, 'selected': False, 'text': '<p><code>perl -d</code> is your friend:</p>\n\n<pre><code>% perl -de 0</code></pre>\n'}, {'answer_id': 73689, 'author': 'Clinton Pierce', 'author_id': 8173, 'author_profile': 'https://Stackoverflow.com/users/8173', 'pm_score': 4, 'selected': False, 'text': '<p>You can always just drop into the built-in debugger and run commands from there.</p>\n\n<pre><code>   perl -d -e 1\n</code></pre>\n'}, {'answer_id': 73698, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 4, 'selected': False, 'text': '<p>There isn\'t an interactive console for Perl built in like Python does.  You can however use the Perl Debugger to do debugging related things.  You turn it on with the -d option, but you might want to check out \'man perldebug\' to learn about it.</p>\n<p>After a bit of googling, there is a separate project that implements a Perl console which you can find at\n<a href="https://web.archive.org/web/20170726140417/http://www.sukria.net/perlconsole.html" rel="nofollow noreferrer">Perl Console - Perl code interactive evaluator with completion</a>.</p>\n<p>Hope this helps!</p>\n'}, {'answer_id': 73703, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 9, 'selected': True, 'text': '<p>You can use the perl debugger on a trivial program, like so:</p>\n\n<pre><code>perl -de1\n</code></pre>\n\n<p>Alternatively there\'s <a href="http://search.cpan.org/~sukria/perlconsole-0.4/perlconsole" rel="noreferrer"><em>Alexis Sukrieh</em>\'s Perl Console</a> application, but I haven\'t used it.</p>\n'}, {'answer_id': 73742, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 4, 'selected': False, 'text': '<p>I use the command line as a console:</p>\n\n<pre><code>$ perl -e \'print "JAPH\\n"\'\n</code></pre>\n\n<p>Then I can use my <em>bash</em> history to get back old commands.  This does not preserve state, however.</p>\n\n<p>This form is most useful when you want to test "one little thing" (like when answering Perl questions).  Often, I find these commands get scraped verbatim into a shell script  or makefile.</p>\n'}, {'answer_id': 73765, 'author': 'shelfoo', 'author_id': 3444, 'author_profile': 'https://Stackoverflow.com/users/3444', 'pm_score': 3, 'selected': False, 'text': '<p>You could look into psh here: <a href="http://gnp.github.io/psh/" rel="noreferrer">http://gnp.github.io/psh/</a></p>\n\n<p>It\'s a full on shell (you can use it in replacement of bash for example), but uses perl syntax.. so you can create methods on the fly etc.</p>\n'}, {'answer_id': 73780, 'author': 'Michael Carman', 'author_id': 8233, 'author_profile': 'https://Stackoverflow.com/users/8233', 'pm_score': 3, 'selected': False, 'text': '<p>Perl doesn\'t have a console but the debugger can be used as one. At a command prompt, type <code>perl -de 1</code>. (The value &quot;1&quot; doesn\'t matter, it\'s just a valid statement that does nothing.)</p>\n<p>There are also a couple of options for a Perl shell:<br />\n<a href="https://web.archive.org/web/20120522111043/http://perldoc.perl.org/perlfaq3.html#Is-there-a-Perl-shell%3f" rel="nofollow noreferrer">Archived &quot;perlfaq3&quot; page which contain question &quot;Is there Perl Shell?&quot;</a></p>\n<p>For more information read <a href="https://perldoc.perl.org/perlfaq3" rel="nofollow noreferrer">perlfaq3</a> (current version).</p>\n'}, {'answer_id': 73868, 'author': 'runrig', 'author_id': 10415, 'author_profile': 'https://Stackoverflow.com/users/10415', 'pm_score': 1, 'selected': False, 'text': '<p>Also look for ptkdb on CPAN:\n<a href="http://search.cpan.org/search?query=ptkdb&amp;mode=all" rel="nofollow noreferrer">http://search.cpan.org/search?query=ptkdb&amp;mode=all</a></p>\n'}, {'answer_id': 73896, 'author': 'amoore', 'author_id': 7573, 'author_profile': 'https://Stackoverflow.com/users/7573', 'pm_score': 5, 'selected': False, 'text': '<p>I think you\'re asking about a REPL (Read, Evaluate, Print, Loop) interface to perl. There are a few ways to do this:</p>\n<ul>\n<li>Matt Trout has <a href="https://web.archive.org/web/20100921094613/http://chainsawblues.vox.com/library/post/a-perl-read-excute-print-loop-repl.html" rel="nofollow noreferrer">an article</a> that describes how to write one</li>\n<li>Adriano Ferreira <a href="https://web.archive.org/web/20150905151804/http://use.perl.org/use.perl.org/articlea9a7.html?sid=07/08/30/1729255" rel="nofollow noreferrer">has described some options</a></li>\n<li>and finally, you can hop on IRC at irc.perl.org and try out one of the eval bots in many of the popular channels. They will evaluate chunks of perl that you pass to them.</li>\n</ul>\n'}, {'answer_id': 74119, 'author': 'Dave Rolsky', 'author_id': 9832, 'author_profile': 'https://Stackoverflow.com/users/9832', 'pm_score': 6, 'selected': False, 'text': '<p>Not only did Matt Trout write an article about a REPL, he actually wrote one - <a href="http://search.cpan.org/dist/Devel-REPL" rel="noreferrer">Devel::REPL</a></p>\n\n<p>I\'ve used it a bit and it works fairly well, and it\'s under active development.</p>\n\n<p>BTW, I have no idea why someone modded down the person who mentioned using "perl -e" from the console. This isn\'t really a REPL, true, but it\'s fantastically useful, and I use it all the time.</p>\n'}, {'answer_id': 76154, 'author': 'raldi', 'author_id': 7598, 'author_profile': 'https://Stackoverflow.com/users/7598', 'pm_score': 5, 'selected': False, 'text': '<p>I wrote a script I call "psh":</p>\n\n<pre><code>#! /usr/bin/perl\n\nwhile (&lt;&gt;) {\n  chomp;\n  my $result = eval;\n  print "$_ = $result\\n";\n}\n</code></pre>\n\n<p>Whatever you type in, it evaluates in Perl:</p>\n\n<pre><code>&gt; gmtime(2**30)\ngmtime(2**30) = Sat Jan 10 13:37:04 2004\n\n&gt; $x = \'foo\'\n$x = \'foo\' = foo\n\n&gt; $x =~ s/o/a/g\n$x =~ s/o/a/g = 2\n\n&gt; $x\n$x = faa\n</code></pre>\n'}, {'answer_id': 80890, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>re.pl from Devel::REPL</p>\n'}, {'answer_id': 80900, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Sepia and PDE have also own REPLs (for GNU Emacs).</p>\n'}, {'answer_id': 90390, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>See also <a href="https://web.archive.org/web/20090109221511/http://blog.jrock.us/articles/Stylish%20REPL.pod" rel="nofollow noreferrer">Stylish REPL (for GNU Emacs)</a></p>\n'}, {'answer_id': 91565, 'author': 'ysth', 'author_id': 17389, 'author_profile': 'https://Stackoverflow.com/users/17389', 'pm_score': 3, 'selected': False, 'text': "<p>I always did:</p>\n\n<pre><code>rlwrap perl -wlne'eval;print$@if$@'\n</code></pre>\n\n<p>With 5.10, I've switched to:</p>\n\n<pre><code>rlwrap perl -wnE'say eval()//$@'\n</code></pre>\n\n<p>(rlwrap is optional)</p>\n"}, {'answer_id': 18843800, 'author': 'KIM Taegyoon', 'author_id': 1941928, 'author_profile': 'https://Stackoverflow.com/users/1941928', 'pm_score': 3, 'selected': False, 'text': '<p>Read-eval-print loop:</p>\n\n<pre><code>$ perl -e\'while(&lt;&gt;){print eval,"\\n"}\'\n</code></pre>\n'}, {'answer_id': 22840242, 'author': 'Ján Sáreník', 'author_id': 1255163, 'author_profile': 'https://Stackoverflow.com/users/1255163', 'pm_score': 5, 'selected': False, 'text': '<p>If you want history, use <a href="https://linux.die.net/man/1/rlwrap" rel="noreferrer">rlwrap</a>. This could be your <code>~/bin/ips</code> for example:</p>\n<pre><code>#!/bin/sh\necho \'This is Interactive Perl shell\'\nrlwrap -A -pgreen -S&quot;perl&gt; &quot; perl -wnE\'say eval()//$@\'\n</code></pre>\n<p>And this is how it looks like:</p>\n<pre><code>$ ips\nThis is Interactive Perl shell\nperl&gt; 2**128\n3.40282366920938e+38\nperl&gt; \n</code></pre>\n'}, {'answer_id': 28372724, 'author': 'Eric Johnson', 'author_id': 58089, 'author_profile': 'https://Stackoverflow.com/users/58089', 'pm_score': 4, 'selected': False, 'text': '<p>There are two popular Perl REPLs.</p>\n\n<ol>\n<li><a href="https://metacpan.org/pod/Devel::REPL" rel="noreferrer">Devel::REPL</a> is great.</li>\n<li>But IMO <a href="https://metacpan.org/pod/Reply" rel="noreferrer">Reply</a> is better. </li>\n</ol>\n'}, {'answer_id': 31283257, 'author': 'mklement0', 'author_id': 45375, 'author_profile': 'https://Stackoverflow.com/users/45375', 'pm_score': 3, 'selected': False, 'text': '<p><sup>Update: I\'ve since created a downloadable REPL - see <a href="https://stackoverflow.com/a/32798002/45375">my other answer</a>.</sup></p>\n\n<p>With the benefit of hindsight:</p>\n\n<ul>\n<li>The <strong>third-party solutions</strong> mentioned among the existing answers are either <strong>cumbersome to install and/or do not work without non-trivial, non-obvious additional steps</strong> - some solutions appear to be at least half-abandoned.</li>\n<li><strong>A usable REPL needs the readline library for command-line-editing keyboard support and history support</strong> - ensuring this is a trouble spot for many third-party solutions.</li>\n<li>If you install CLI <strong><code>rlwrap</code>, which provides readline support to any command, you can combine it with a simple Perl command to create a usable REPL</strong>, and thus make do without third-party REPL solutions.\n\n<ul>\n<li>On OSX, you can install <code>rlwrap</code> via <a href="http://brew.sh" rel="nofollow noreferrer">Homebrew</a> with <code>brew install rlwrap</code>.</li>\n<li>Linux distros should offer <code>rlwrap</code> via their respective package managers; e.g., on Ubuntu, use <code>sudo apt-get install rlwrap</code>.</li>\n<li><strong>See <a href="https://stackoverflow.com/a/22840242/45375">Ján Sáreník\'s answer</a> for said combination of <code>rlwrap</code> and a Perl command.</strong></li>\n</ul></li>\n</ul>\n\n<hr>\n\n<p><strong>What you do NOT get</strong> with Ján\'s answer:</p>\n\n<ul>\n<li>auto-completion</li>\n<li>ability to enter multi-line statements</li>\n</ul>\n\n<p>The only third-party solution that offers these (with non-trivial installation + additional, non-obvious steps), is <strong><a href="https://github.com/gnp/psh" rel="nofollow noreferrer">psh</a></strong>, but:</p>\n\n<ul>\n<li><p>it hasn\'t seen activity in around 2.5 years</p></li>\n<li><p>its focus is different in that it aims to be a full-fledged <em>shell replacement</em>, and thus works like a traditional shell, which means that it doesn\'t automatically evaluate a command as a <em>Perl</em> statement, and requires an explicit output command such as <code>print</code> to print the result of an expression.</p></li>\n</ul>\n\n<hr>\n\n<p><a href="https://stackoverflow.com/a/22840242/45375">Ján Sáreník\'s answer</a> can be improved in one way:</p>\n\n<ul>\n<li>By default, it <strong>prints arrays/lists/hashtables as <em>scalars</em></strong>, i.e., only prints their <em>element count</em>, whereas it would be handy to enumerate their elements instead.</li>\n</ul>\n\n<p>If you install the <strong><code>Data::Printer</code></strong> module with <code>[sudo] cpan Data::Printer</code> as a one-time operation, you can load it into the REPL for use of the <strong><code>p()</code> function, to which you can pass lists/arrays/hashtables for enumeration.</strong></p>\n\n<p>Here\'s an <strong>alias named <code>iperl</code> with readline and <code>Data::Printer</code> support</strong>, which can you put in your POSIX-like shell\'s initialization file (e.g., <code>~/.bashrc</code>):</p>\n\n<pre><code>alias iperl=\'rlwrap -A -S "iperl&gt; " perl -MData::Printer -wnE \'\\\'\'BEGIN { say "# Use `p @&lt;arrayOrList&gt;` or `p %&lt;hashTable&gt;` to print arrays/lists/hashtables; e.g.: `p %ENV`"; } say eval()//$@\'\\\'\n</code></pre>\n\n<p>E.g., you can then do the following to print all environment variables via hashtable <code>%ENV</code>:</p>\n\n<pre><code>$ iperl        # start the REPL\niperl&gt; p %ENV  # print key-value pairs in hashtable %ENV\n</code></pre>\n\n<p>As with Ján\'s answer, the <em>scalar</em> result of an expression is <em>automatically</em> printed; e.g.:</p>\n\n<pre><code>iperl&gt; 22 / 7  # automatically print scalar result of expression: 3.14285714285714\n</code></pre>\n'}, {'answer_id': 32798002, 'author': 'mklement0', 'author_id': 45375, 'author_profile': 'https://Stackoverflow.com/users/45375', 'pm_score': 4, 'selected': False, 'text': '<p>I\'ve created <a href="https://github.com/mklement0/perli" rel="noreferrer"><code>perli</code></a>, a <strong>Perl REPL</strong> that runs on <strong>Linux, macOS, and Windows</strong>.</p>\n\n<p>Its focus is automatic result printing, convenient documentation lookups, and easy\ninspection of regular-expression matches.<br>\nYou can see screenshots <a href="https://github.com/mklement0/perli#examples" rel="noreferrer">here</a>.</p>\n\n<p>It works <strong>stand-alone</strong> (has no dependencies other than Perl itself), but <strong>installation of <a href="https://github.com/hanslub42/rlwrap" rel="noreferrer"><code>rlwrap</code></a> is strongly recommended</strong> so as to support command-line editing, persistent command history, and tab-completion - read more <a href="https://github.com/mklement0/perli#supported-platforms-and-prerequisites" rel="noreferrer">here</a>.</p>\n\n<p><strong>Installation</strong></p>\n\n<ul>\n<li><p>If you happen to have Node.js installed:</p>\n\n<pre><code>npm install -g perli\n</code></pre></li>\n<li><p>Otherwise:</p>\n\n<ul>\n<li><p><em>Unix</em>-like platforms: Download <a href="https://raw.githubusercontent.com/mklement0/perli/stable/bin/perli" rel="noreferrer">this script</a> as <code>perli</code> to a folder in your system\'s path and make it executable with <code>chmod +x</code>.</p></li>\n<li><p><em>Windows</em>: Download the <a href="https://raw.githubusercontent.com/mklement0/perli/stable/bin/perli" rel="noreferrer">this script</a> as <code>perli.pl</code> (note the <code>.pl</code> extension) to a folder in your system\'s path.<br>\nIf you don\'t mind invoking Perli as <code>perli.pl</code>, you\'re all set.<br>\nOtherwise, create a batch file named <code>perli.cmd</code> in the same folder with the following content: <code>@%~dpn.pl %*</code>; this enables invocation as just <code>perli</code>.</p></li>\n</ul></li>\n</ul>\n'}, {'answer_id': 35815564, 'author': 'gavenkoa', 'author_id': 173149, 'author_profile': 'https://Stackoverflow.com/users/173149', 'pm_score': 2, 'selected': False, 'text': '<p>Under Debian/Ubuntu:</p>\n\n<pre><code>$ sudo apt-get install libdevel-repl-perl\n$ re.pl\n\n$ sudo apt-get install libapp-repl-perl\n$ iperl\n</code></pre>\n'}, {'answer_id': 37551820, 'author': 'Davor Cubranic', 'author_id': 552683, 'author_profile': 'https://Stackoverflow.com/users/552683', 'pm_score': 2, 'selected': False, 'text': '<p>Matt Trout\'s <a href="http://shadow.cat/blog/matt-s-trout/mstpan-17/" rel="nofollow">overview</a> lists five choices, from <code>perl -de 0</code> onwards, and he recommends <a href="https://metacpan.org/pod/Reply" rel="nofollow"><code>Reply</code></a>, if extensibility via plugins is important, or <code>tinyrepl</code> from <a href="https://metacpan.org/pod/Eval::WithLexicals" rel="nofollow"><code>Eval::WithLexicals</code></a>, for a minimal, pure-perl solution that includes readline support and lexical persistence.</p>\n'}, {'answer_id': 61923730, 'author': 'Ross Attrill', 'author_id': 556644, 'author_profile': 'https://Stackoverflow.com/users/556644', 'pm_score': 0, 'selected': False, 'text': '<p>You can do it online (like many things in life) here:</p>\n\n<p><a href="https://www.tutorialspoint.com/execute_perl_online.php" rel="nofollow noreferrer">https://www.tutorialspoint.com/execute_perl_online.php</a></p>\n'}, {'answer_id': 67925304, 'author': 'HappyFace', 'author_id': 1410221, 'author_profile': 'https://Stackoverflow.com/users/1410221', 'pm_score': 0, 'selected': False, 'text': '<p>You can use <code>org-babel</code> in <code>emacs</code>; Open an <code>org-mode</code> file, i.e., <code>tmp.org</code>, and then you can do:</p>\n<pre><code>#+begin_src perl :results output\n@a = (1,5,9);\nprint ((join &quot;, &quot;, @a) . &quot;\\n&quot;);\n$b = scalar @a;\nprint &quot;$#a, $b\\n&quot;;\nprint &quot;$#a, &quot; . @a . &quot;\\n&quot;;\nprint join &quot;, &quot;, 1..$#a; print &quot;\\n&quot;;\nprint join &quot;, &quot;, @a[0..$#a]\n#+end_src\n</code></pre>\n<p>Pressing <code>CTRL-c CTRL-c</code> evals the block:</p>\n<pre><code>#+RESULTS:\n#+begin_example\n1, 5, 9\n2, 3\n2, 3\n1, 2\n1, 5, 9\n#+end_example\n</code></pre>\n<p>I am not sure what emacs config this needs to work, but I think you can just install <a href="https://github.com/hlissner/doom-emacs" rel="nofollow noreferrer">https://github.com/hlissner/doom-emacs</a> and enable its <code>perl</code> and <code>org-mode</code> modules.</p>\n'}]
['https://Stackoverflow.com/questions/73667', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5475/']