in reply to Perl as interactive Shell?

For instance I'm aware of easy piping with | and redirection >

IPC::Run perhaps? From its synopsis:

run \@cat, '<', "in.txt", '>>', "out.txt", '2>>', "err.txt"; run \@cat, '|', \@gzip;
with less and ls implemented as subs (see also Shell)

Excuse the plug, but I wrote a module that presents a similar interface, but it has more error handling, less problems with shell quoting, and additional capabilities: IPC::Run3::Shell.

There are also several modules I've found very useful in writing shorter code, such as Path::Class and File::Find::Rule.

what are the fundamental obstacles hindering Perl to be used instead of Bash and or PowerShell?

I imagine one issue that might come up is variable scoping, i.e. how long do variables last once they're created - I imagine in a long-running shell, this might end up being a bit of a memory leak.

Replies are listed 'Best First'.
Re^2: Perl as interactive shell?
by LanX (Saint) on May 13, 2017 at 13:55 UTC
    Thanks that's nice! :)

    IPC::Run is certainly interesting, but it'd need a nicer syntax to be usable in a CLI.

    IPC::Run3::Shell already looks much better, but I'd opt to use it primarily for non-standard executables which can't be implemented in Perl. (like with powertools )

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

      IPC::Run3::Shell already looks much better, but I'd opt to use it primarily for non-standard executables which can't be implemented in Perl.

      Agreed, and I wouldn't normally shell out to things that Perl can do natively either. Sometimes, if I'm writing a one-off script that's not meant for production, I might call find, but then again I've started using File::Find::Rule more often (even though I've measured it and it's not nearly as fast as File::Find or find). Anyway, I grepped my code and here are two examples of how I've actually used the module, in the first one I remember that in that particular case, simply calling the convert program was much faster to implement than getting Image::Magick set up. Especially if the scripts are not meant for a production environment, speed of development is often what it's about; depending on what one has the most experience with, remembering or looking up the command-line arguments can be faster than finding the appropriate Perl module.

      use IPC::Run3::Shell { fail_on_stderr=>1 }, qw/convert/; convert $img, '-auto-orient', '-resize', '300x300', $thumb; use IPC::Run3::Shell qw/gs/; gs({fail_on_stderr=>1,show_cmd=>1}, '-o',$OUTPUT, '-sDEVICE=pdfwrite', ..., '-f',$INPUT);

      Update: Minor re-wording.