Converting Other Languages to Perl
If you’ve got old sed and awk programs that you wish were written in Perl, you’re in luck. Not only can Perl do everything that those can do, there’s also a conversion program available, and it’s probably already installed on your system. Check the documentation for s2p (for converting from sed) or a2p (for converting from awk).[*] Since programs don’t write programs as well as people do, the results won’t necessarily be the best Perl—but it’s a start, and it’s easy to tweak. The translated program may be faster or slower than the original, too. But after you’ve fixed up any gross inefficiencies in the machine-written Perl code, it should be comparable.
Do you have C algorithms you want to use from Perl? Well, you’ve still
got some luck on your side; it’s not too hard to put C code into a
compiled module that can be used from Perl. In fact, any language that
compiles to make object code can generally be used to make a module. See
the perlxs manpage, and the Inline module, as well as the SWIG
system.
Do you have a shell script that you want to convert to Perl? Your luck
just ran out. There’s no automatic way to convert shell to Perl. That’s
because the shell hardly does anything by itself; it spends all of its
time running other programs. Sure, we could make a program that would
mostly just call system for each line of the shell, but that would be much slower than just letting the shell do things in the first place. It really takes a human level of ...