Hacker News new | past | comments | ask | show | jobs | submit login

If you really want to learn Perl, you must install the read-eval-print loop (REPL) utility. If you have never used this utility, I will have serious grounds to doubt your Perl skills.

Unlike Ruby or Python (or most other modern high-level programming languages), Perl does not come with an interactive REPL shell, which makes no sense at all, since, due to Perl's obscure syntax, someone trying out Perl would benefit at least twice as much from a REPL shell than someone learning Ruby or Python. Fortunately, the Devel::REPL package remedies this. Installing it is super-simple:

    $ sudo /usr/bin/perl -MCPAN -e shell
    > install Devel::REPL
Once installed, simply open your terminal and run:

    $ re.pl
Once you have the REPL shell running, you can pretty much copy-and-paste into it examples from this tutorial (or any other) and watch what Perl has to say in response.



If you have never used this utility, I will have serious grounds to doubt your Perl skills.

Doubt away.

I have never used that utility. Yet I have been programming Perl since the 90s, and am one of the top 10 posters on Perlmonks. (My nick there is tilly.)

Care to re-evaluate your criteria?


> I have been programming Perl since the 90s, and am one of the top 10 posters on Perlmonks... Care to re-evaluate your criteria?

Yes, for you, I can :) My post was meant only to advocate interactive learning (which I came believe to be faster than the usual code/modify/run cycle). Few things (if any) can beat 15 years of intense experience. Most people, though, whom one is likely to encounter in the real world who claim to know Perl will only have used it for a year or two, probably in combination with something else.


I'm in exactly the same boat. I've been doing Perl for 14 years, and never use a REPL. Occasionally I'll hit 'perl -e ""' on the command line, which I guess is a similar idea...


Hey I didn't mean to offend Perl long-timers. See my response to btilly...

Hacker News is a bit of an exception to what you find in the real world (where 3 years of experience with a language can be considered as better than average).


You can also go into the debug shell (which is REPL) by giving it some valid statement: Here is an example:

shell> perl -de 1

This will take you into the perl debug shell (after evaluating the string "1" which is true).


That works of course, but Devel::REPL is much more convenient: (1) you don't have to end your statements with backslashes -- you can paste whole blocks as is, (2) you immediately see what your statement evaluates to, for example typing "42" in Perl debugger simply begins another prompt while typing it in a true REPL returns the value that your statement evaluates to (i.e. "42") -- which is not a big deal with simple statements but gets interesting once you start evaluating regular expressions, for example, (3) Devel::REPL remembers what you typed (or at least it works the same way as your system shell), (4) it is really easy to work out complicated things in Devel::REPL -- see for example this case of currying a function:

   $ my $x = sub { my $x = shift; return sub { $x . shift } }
   $CODE1 = sub { # this is what is returned by Devel::REPL
           package Devel::REPL::Plugin::Packages::DefaultScratchpad;
           use warnings;
           use strict 'refs';
           my $x = shift @_;
           return sub {
             $x . shift(@_);
           }
           ;
         };
    
    $ $x->('hello ')->('world');
    hello world


> sudo /usr/bin/perl -MCPAN -e shell This reminds me of a gripe with Perl: If you are on a machine where you lack root, everything is a lot less convenient.


This is true, but local::lib has come along and made things much easier:

http://search.cpan.org/~apeiron/local-lib-1.008004/lib/local...

This very handily includes instructions on how to bootstrap its own installation.


simply: $ sudo cpan Devel::REPL

also you can do this: $ perl -e 'print "Hello World!\n";'


Huh, I thought "everyone" used perlbrew now?

It has been on my todo to try the REPL for a long time, but since Perl is the most powerful command line tool in bash, I've never seen a reason to use an interactive tool.

  alias p=perl
  p -e '...'
  p -ne '....'
  # etc.
Edit: With powerful I didn't mean "rm -rf", etc. :-)


I don't use perlbrew. Haven't tried it, since installing your own Perl by-hand is easy enough.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: