Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: RFC: UNIX shell to Perl converter

by NovMonk (Chaplain)
on Oct 09, 2006 at 17:08 UTC ( #577225=note: print w/replies, xml ) Need Help??


in reply to RFC: UNIX shell to Perl converter

Funny you should mention this, because that's just what my company is about to do. Here's why:

We have a Boatload of Shell scripts that control various parts of our processes. No standards, very hard to find what's broken when something changes, etc. We want to replace the functionalty of all these scripts with Perl modules and an overarching Perl program to call them, And we want to incorporate testing modules into the process up front so that we can enforce standards, know what's broken when we make changes, and make it easier for new folks to see what's going on.

I'd love to see if anyone has done something to automate some of the process, but I imagine we'll be doing a lot of the conversion manually, simply because there's a lot of garbage accumulated that needs cleared away.

Which is a long way of saying, good luck, and I look forward to other answers.

NovMonk

Replies are listed 'Best First'.
Re^2: RFC: UNIX shell to Perl converter
by BerntB (Deacon) on Oct 09, 2006 at 22:42 UTC
    Sounds like a fun project with lots of pain. :-)

    How about about patching 'bash' to show what is done? There might even be some debugging stuff in there already, which could be used?

    Then you could get a log of:

    Line X: run program "a" and store output into "b". Line X+1: Do something if $? == c
    It should make it easier to generate Perl code and you could get the return codes, etc.

    Hmm... could generate Perl programs that just did "system" calls and then rewrite them by parts.

      Yep, I looked at that. I also considered 'lifting' the parser from Bash rather than writing my own, seemed daft to write my own parser when there was already a perfectly good one there. Unfortunately I found that it was not so easy to extract it as a separate entity, it is integrated into the whole product. Someone like Chet Ramey could probably do it, not me.
      As for the pain, this is working out to be almost as good as whipping myself with nettles - Ahhhhh. (No nettles were harmed in the writing of this post).
Re^2: RFC: UNIX shell to Perl converter
by cdarke (Prior) on Oct 09, 2006 at 17:35 UTC
    Thanks for the encouragement, yours is exactly the kind of project this is for. Fancy helping with the testing later?
Re^2: RFC: UNIX shell to Perl converter
by chrism01 (Friar) on Oct 17, 2006 at 06:06 UTC
    It seems to me you've got 3 options there:

    1. auto-translate;
    con: GIGO ie crud shell input => crud Perl output.
    pro: quick/low effort

    2. Hand code new Perl modules as you go.
    con: Takes a while, same cruddy architecture as original
    pro: you'll get good, maintainable Perl that does logging etc. Also means you can replace shell files gradually, instead of the big bang approach.

    3. Design a new/better ctrl system in Perl from scratch.
    pro: Gives you better code and more integrated approach.
    con: more effort upfront & big bang approach

    I once had to do a FORTRAN to C job (Y2K) and we originally tried option (1.), but I ended up doing a fair bit of (2.) to make it work properly.
    A straight option (2.) approach might have been quicker in the long run, otherwise you end up with weird looking code due to the auto-converter.

    HTH Cheers
    Chris

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2022-05-29 04:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?