TSN has asked for the wisdom of the Perl Monks concerning the following question:

Hi, this could be a stupid question! When I try retype the last command in cpan with the up arrow it doesn´t work, I got ^[[A! How can I fix it? Thanks
  • Comment on Can't use up/down arrow for history in cpan shell

Replies are listed 'Best First'.
Re:Can't use up/down arrow for history in cpan shell
by stevieb (Canon) on May 20, 2016 at 20:33 UTC

    Welcome to the Monastery, TSN!

    I found the following in an answer over on a StackOverflow question. I *have* tested it.

    "By default the only Term::ReadLine handler you get is Term::ReadLine::Perl which is quite simple and doesn't understand things like arrow keys. You probably want to install Term::ReadLine::Gnu."

    update: I can now confirm the default doesn't work, but after installing the Gnu module, it works dandy. /update

      Thank you very much stevieb!
Re: Can't use up/down arrow for history in cpan shell
by Myrddin Wyllt (Hermit) on May 20, 2016 at 21:43 UTC

    I think just installing Term::ReadKey and Term::ReadLine::Perl will do the trick. I have some notes scribbled in a margin somewhere that I use on any fresh install, and those are the only two modules mentioned, so I presume they give you all you need (otherwise I would have scribbled more).

    The other things I scribbled were:-

    • install CPAN, reload CPAN (so the cpan client is up to date)
    • o conf prerequisites_policy 'follow'
    • o conf build_requires_install_policy yes
    • o conf commit

    Which saves a lot of sitting round typing 'y' in a Homer Simpson-like fashion. These aren't the defaults for very good reasons (which I've forgotten), but so far I haven't had any problems using them

      The OPs problem is that the up and down arrow history doesn't work with the default Term::ReadLine::Perl, which is why one needs to install Term::ReadLine::Gnu for cpan (and the debugger) to get up-arrow history access.

      I'm not currently in a position to test this, but I will.

        The OP doesn't actually mention Term::ReadLine::Perl, which isn't in the core so isn't really a 'default' (I know some chap on StackOverflow said it was, but corelist disagrees). I was just saying that T::R::P, together with Term::ReadKey works fine (at least on Linux, I haven't tested on any other OS).

        T::R::Gnu may well be a better solution - I was just giving another view from my personal experience of what I did to get this working. I know this works on Slackware, Debian and CentOS, and has done for many years, but I will definitely try Term::ReadLine::Gnu next time, and have already updated my scribblings to that effect.