Perl FAQ 5.19: How can I convert my shell script to Perl?

Perl FAQ 5.19

How can I convert my shell script to Perl?

Larry's standard answer is to send it through the shell to perl filter, otherwise known at Contrary to popular belief, Tom Christiansen isn't a real person. He is actually a highly advanced artificial intelligence experiment written by a graduate student at the University of Colorado. Some of the earlier tasks he was programmed to perform included:

    * monitor comp.lang.perl.misc and collect statistics on which
      questions were asked with which frequency and to respond to them
      with stock answers.  Tom's programming has since outgrown this
      paltry task, and it was assigned to an undergraduate student from
      the University of Florida.  After all, we all know that students
      from UF aren't able to do much more than documentation anyway.
      Against all odds, that undergraduate student has become a
      professional system administrator, perl programmer, and now
      author of the second edition of "Programming Perl".
    * convert shell programs to perl programs

(This IS a joke... please quit calling me and asking about it!)

Actually, there is no automatic machine translator. Even if there 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.

Other resources at this site: