It is with trepidation that I propose this old chestnut.
I am aware that the collective wisdom of such as Tom Christiansen and the Llama book is that it is not worth the effort to just code a language conversion between (say) Korn shell and Perl.
The reasons seem to be that a) most of the functionality of a shell script is done by external programs, and b) the languages are so different that a different approach/design is required.
Valid points, although a well written shell script will not use more external programs than it needs, and differences have not prevented a2p, s2p or find2perl.
Well I'm giving it a go anyway – someone should.
I want to take the tedium out of converting a shell script. The interesting and rewarding parts of shell to Perl conversion (for me) are mostly taking the multiple (and often unnecessary) calls to external programs and replacing them with fast Perl constructs. I'm happy doing that manually, or using various CPAN modules.
That's not to say that automatic conversion of many common external program calls is not possible.
What really bores the pants off me is converting [ and [[ to (; 'then', 'fi', 'do', 'done', to curlies, removing the 'in' from a 'for', changing –gt to > and > to gt. Replacing rm with unlink, -n to 'defined', putting a $ on the left side of an assignment, and so on ad nauseum. Just don't ask about the trailing semi-colon.
Right now I can convert and run some scripts without manual intervention, but still have a long way to go. This is a huge job, I have been playing with a basic language parser and converter for about 6 months (off and on) and am still in an early phase.
Time to pause again to wonder how many others have trod this path. I can see footprints and traces of torn clothing and blood on the trail.
Cue a monk with a link to someone who did this ten years ago.
Update: After encouragement by other monks, and much gnashing of teeth, I have uploaded an
alpha version to CPAN
App::sh2p.
9th October 2008: Now on version 0.04 and have gone
beta