2

I'd like arrow keys to work for command history in perl debugger. This solution looks good, so since I'm using ubuntu, I tried

sudo aptitude install libterm-readline-gnu-perl

But, I still get the ^[[A and ^[[B echoed back in the perl debugger instead of previous/next commands.

I have found this is specifically an issue within my perlbrew envinronment. If I run /usr/bin/perl -d the arrow keys do work (ie, the install fixed it only for that perl).

How do I get the debugger to work under perlbrew?

As a last-ditch effort, within my perlbrew environment I tried cpanm Term::ReadLine::Gnu but got the error

Could not find neither libtermcap.a, libncurses.a, or libcurses.

I could start installing more libraries, but it feels like I'm missing something else, since it's only a problem affecting Perlbrew.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Randall
  • 2,859
  • 1
  • 21
  • 24
  • 3
    You're not missing "something else." It's only affecting perlbrew because your perlbrew perl doesn't have Term::Readline::Gnu installed. – ThisSuitIsBlackNot Jul 18 '16 at 19:13
  • OK, true (confirmed it's installed under `/usr/lib/perl5`, from `libterm-readline-gnu-perl`). But then why the cpanm errors under perlbrew? I.e., why does it work under `/usr/bin/perl -d` *without* those libraries being installed? – Randall Jul 18 '16 at 19:32
  • 1
    That error is raised when the libraries can't be found in `$Config{libpath}`. Run `perl -MConfig -le'print $Config{libpth}'` to see which directories are being searched. Either the libraries are installed but your perlbrew perl is looking in the wrong directories, or the libraries aren't installed but they are linked statically in libterm-readline-gnu-perl. – ThisSuitIsBlackNot Jul 18 '16 at 19:47
  • Ah - I hadn't thought about static linking. That must be it; `find` doesn't return results for any of the library names. The perlbrew `$Config{libpath}` searches a superset of the /usr/bin/perl directories. – Randall Jul 18 '16 at 20:00
  • It's only working for your system Perl because you only installed the module for your system Perl. – ikegami Jul 18 '16 at 21:07

2 Answers2

2

Perl modules installed via your distribution's package system are only available in the perl from your distribution (i.e. /usr/bin/perl). Other perl installations (e.g. those managed by perlbrew) are not affected. That's why other perls don't see Term::ReadLine::Gnu.

Installing Term::ReadLine::Gnu from within the perlbrew environment (e.g. via cpan or cpanm) is the right solution. The error you're getting is probably caused by missing development headers (Term::ReadLine::Gnu is a wrapper around the readline C library, so it needs headers to build). Try installing ncurses-dev (with aptitude), then run cpanm again.

melpomene
  • 84,125
  • 8
  • 85
  • 148
  • Dependency hell: `rlver.c:3:31: fatal error: readline/readline.h: No such file or directory` But that is why I wanted to make sure I wasn't missing something else first :-) – Randall Jul 18 '16 at 20:36
1

Installing the packages @melpomene suggests does do the trick.

But I found another solution that does not require the dev packages (and, hence, does not require root). Either of the following CPAN packages can be used on their own:

  • Term::ReadLine::Perl (Perl implementation of Readline libraries)
  • Term::Readline::Zoid (Pure Perl implementation of Readline libraries)

Since Perlbrew is sometimes (often?) used in environments where you don't have root, this is probably a more convenient solution.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Randall
  • 2,859
  • 1
  • 21
  • 24