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

Is there a Perl program that would convert any shell script to a perl program? Thanks for your time. Andre

Replies are listed 'Best First'.
Re: Shell converted to Perl
by clemburg (Curate) on Aug 09, 2001 at 21:07 UTC

    No. There is no such thing.

    The standard answer to this in the Perl FAQ (old versions) was:

    2.32) How can I convert my shell script to Perl? Larry's standard answer for this is to send your script to me (Tom Christiansen) with appropriate supplications and offerings. :-( That's because there's no automatic machine translator. Even if you were, you wouldn't gain a lot, as most of the external programs would still get called. It's the same problem as blind translation into C: you're still apt to be bogged down by exec()s. You have to analyze the dataflow and algorithm and rethink it for optimal speedup. It's not uncommon to see one, two, or even three orders of magnitude of speed difference between the brute-force and the recoded approaches.

    For the newest answer, try:

    perldoc -q shell.+script

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

      For various values of "no such", merlyn actually wrote something along those lines.

        Ah! Thanks! I did not know that. Things change ... ;-) ...

        Christian Lemburg
        Brainbench MVP for Perl
        http://www.brainbench.com

Re: Shell converted to Perl
by abstracts (Hermit) on Aug 09, 2001 at 20:54 UTC
    Hello

    When you say shell, do you means bash, csh, tcsh, ksh, zsh, or what? There is no automated way to convert from any of these shell languages to perl that I know of. The simplest way would be to look at the script, figure out how it works, and then rewrite it in Perl.

    Hope this helps,,,

    Aziz,,,

    Update: There are also es, esh, eshell, kiss, lsh, pdksh, sash, and many more available on my Debian box.

Re: Shell converted to Perl
by TStanley (Canon) on Aug 10, 2001 at 03:11 UTC
    Or you can use the Shell module, which is part of the standard distribution of Perl.

    TStanley
    --------
    There's an infinite number of monkeys outside who want to talk to us
    about this script for Hamlet they've worked out
    -- Douglas Adams/Hitchhiker's Guide to the Galaxy