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

just taught myself the basics of perl; it's cool, but easy to get lost.
current project: convert a bunch of ugly, cascading csh scripts to perl.
how: by hand(ugh.) or by translator.
petition: is there a csh-to-perl translator around? preferably one that doesn't generate obfuscated perl 8-)

Edit: 2001-03-03 by neshura

Replies are listed 'Best First'.
Re: csh-perl xlator
by Dominus (Parson) on Dec 16, 2000 at 07:29 UTC
    There isn't one at all, obfuscated or otherwise.

    The thing that has always prevented anyone from writing such a program is that it's very hard! It's easy to do a really bad job, but to do a good job, you have to be very clever. For example, suppose you see this:

    set bar=`echo $foo | awk '{print $5}' | cut -c1-4`
    The obvious (bad) translation is:
    $bar=`echo $foo | awk '{print \$5}' | cut -c1-4`
    But the right translation is:
    $bar = substr((split($foo))[4], 0, 4);
    Anyway, aside from an April Fool's joke that Randal perpetrated a few years ago, there is no shell-to-perl translator that I know of.

      A good learning process it to write a 'bad' or incomplete translator. Just going through and
      TMP="/tmp/cas.$$.out" to: $tmp = "/tmp/cas.$$.out"
      is useful and trying to map if ... ] then to if ( ... ) [ (sorry I'm a ksh fool) can be quite useful both in learning and in moving some of your stuff. The hard parts will still need to be done by hand.

      a

Re: csh-perl xlator
by Corion (Patriarch) on Dec 16, 2000 at 17:12 UTC

    The only known shell -> Perl translator on the internet is Tom Christiansen.

    If you look at the history of porting, it has always been easier to write an emulator that emulates the source machine than to port the program to the target machine. The 8086, Java, C# and Inferno/Dis all follow this concept.

    If you consider the possible pitfalls of writing a general csh to Perl converter, like obscure ways to define arrays, even more obscure ways to access variables and the source (I mean eval) statement, you will see that an emulator is the only way to go ...