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

Hi

I was very surprised to find out at work that the local Win/Activestate/Perl5.16 supports arrow-key navigation of the history of multi-liners typed after a blank 'perl RET'.

For instance this is the sobering effect with my Linux 5.20 installation

~$ perl $a=42; print $a; __END__ 42 ~$ perl ^[[A^[[A^[[A^C # Arrow keys no avail ~$

Term::Readline is of course installed for the debugger, so this can't be the reason.

Now I'm wondering how to activate this feature on Linux too or at least to understand the differences between the OS versions better.

Any insights?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re: Navigating history of STDIN-multiliners after 'perl RET'
by BrowserUk (Patriarch) on Dec 24, 2016 at 16:31 UTC

    The history is provided by cmd.exe not perl.

Re: Navigating history of STDIN-multiliners after 'perl RET'
by kschwab (Vicar) on Dec 25, 2016 at 12:59 UTC

    Bash, for reasons unknown to me, disables the previous-command type functionality when reading from standard input.

    You can get the behavior you're looking for with rlwrap. On my debian-based box, it was simple to install with "apt-get install rlwrap"

    Then, just run "rlwrap perl" instead of "perl", and it should do what you want.

      Hi kschwab

      > Then, just run "rlwrap perl" instead of "perl", and it should do what you want.

      Thanks, I knew rlwrap and it's already installed. :)

      I erroneously thought that on Win I'm able to navigate the whole chunk of code from the last call to perl instead of just reconstruction line after line.

      But it turns out I was wrong.

      Probably there is an option for rlwrap to treat the whole chunk as one line. Have to look into it.

      For me there is a gap to be filled between improvised one-liners and persistent scripts.

      I also tried putting all into a bash heredoc but either my bash foo is too weak or interactive input is treating heredocs differently

      $ perl -e <<___ if(1) { print 44; } ___ No code specified for -e.

      EDIT:

      But while composing this post I noticed that this syntax does what I want:

      $ perl <<___ if(1) { print 44; } ___ 44 # arrow up $ perl <<___ if(1) { print 44; } ___

      Of course on bash only :(

      update

      unfortunately the "solution" I found is messing up STDIN pipes

      lanx@lanx-1005HA:/tmp$ ls |perl -n <<___ print if /a/ ___ lanx@lanx-1005HA:/tmp$ ls |perl -ne ' print if /a/ ' atop.d at-spi2 mkinitramfs_JrDw4Q mkinitramfs-OL_Ahxk1r

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re: Navigating history of STDIN-multiliners after 'perl RET'
by Anonymous Monk on Dec 25, 2016 at 15:14 UTC

    Once you type 'perl RET', an executable named 'perl' will be started. That program (presumably) will go on to read STDIN and execute it as perl script.

    It'd be rather strange for scripts to be self-editing. E.g. your DATA section might contain escape sequences and so on. In theory, one could have perl act differently (launch an IDE) when run on a terminal with no arguments. Via sitecustomize perhaps or by creating a 'perl' wrapper script. You try it, see how it works.

    Or you could do what everyone else does: use perl -e '...' multiliners. Or perhaps echo '...' | perl. In other words, edit/enter the script as part of the command line.