⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appb_25.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>Converting Other Languages to Perl (Learning Perl, 3rd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Randal L. Schwartz and Tom Phoenix" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596001320L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Learning Perl, 3rd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Learning Perl, 3rd Edition" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="appb_24.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"></a></td><td align="right" valign="top" width="228"><a href="appb_26.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">B.25. Converting Other Languages to Perl</h2><p>If you've got old <i class="command">sed</i> and<i class="command">awk</i> <a name="INDEX-1319" /><a name="INDEX-1320" />programs that youwish were written in Perl, you're in luck. Not only can Perl doeverything that those can do, there's also a<a name="INDEX-1321" />conversion program available, andit's probably already installed on your system. Check thedocumentation for <i class="command">s2p</i><a name="INDEX-1322" /> (for converting from<i class="command">sed</i>) or<i class="command">a2p</i><a name="INDEX-1323" /> (for converting from<i class="command">awk</i>).<a href="#FOOTNOTE-421">[421]</a> Since programs don't write programs aswell as people do, the results won't necessarily be the bestPerl -- but it's a start, and it's easy to tweak. Thetranslated program may be faster or slower than the original, too.But after you've fixed up any gross inefficiencies in themachine-written Perl code, it should be comparable.</p><blockquote class="footnote"> <a name="FOOTNOTE-421" /><p>[421]If you're using<i class="command">gawk </i>or <i class="command">nawk </i>or some othervariant, <i class="command">a2p </i>may not be able to convert it. Bothof these conversion programs were written long ago and have had fewupdates except when needed to keep working with new releases ofPerl.</p> </blockquote><p>Do you have C algorithms you want to use from Perl? Well,you've still got some luck on your side; it's not toohard 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 generallybe used to make a module. See the <em class="emphasis">perlxs</em>manpage, and the <tt class="literal">Inline</tt> module, as well as theSWIG system.</p><p>Do you have a shell script that you want to convert to Perl? Yourluck just ran out. There's no automatic way to convert shell toPerl. That's because the shell hardly does anything by itself;it spends all of its time running other programs. Sure, we could makea program that would mostly just call <tt class="literal">system</tt> foreach line of the shell, but that would be much slower than justletting the shell do things in the first place. It really takes ahuman-level of intelligence to see how the shell's use of<i class="command">cut</i>, <i class="command">rm</i>,<i class="command">sed</i>, <i class="command">awk</i>, and<i class="command">grep</i> can be turned into efficient Perl code.It's better to rewrite the shell script from scratch.</p><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="appb_24.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img alt="Home" border="0" src="../gifs/txthome.gif" /></a></td><td align="right" valign="top" width="228"><a href="appb_26.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">B.24. Embedding</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img alt="Book Index" border="0" src="../gifs/index.gif" /></a></td><td align="right" valign="top" width="228">B.26. Converting find Command Lines to Perl</td></tr></table></div><hr width="684" align="left" /><img alt="Library Navigation Links" border="0" src="../gifs/navbar.gif" usemap="#library-map" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -