Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl as interactive shell?

by haukex (Archbishop)
on May 12, 2017 at 15:11 UTC ( [id://1190135]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1190135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found