?? 01_4_12_2.asp.html
字號:
<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>計算機世界網-Perl 語言全面編譯(四)</TITLE></HEAD>
<style>
.a14{font-size:14px;text-indent:25px;line-height:20px}
.f{font-size:18px;color=#0f3ccd}
img{border:0px;}
td,p,input{font-fammily:verdana,宋體;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<center>
<BODY topmargin=2 leftmargin=0>
<style>
.v12{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋體;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<style>
.v13{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v12{font-size:13px;color:"#4C029C";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋體;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<!--頭-->
<table align=center cellpadding="0" cellspacing="0" border="0" width="767">
<tr><td valign=bottom>
<table cellpadding="0" cellspacing="0" border=0>
<tr><td valign=top><img src="ccwlogo3.gif"></td></tr>
<tr><td height="27" valign=top><img src="knowledj.gif" width="207" height="27"></td></tr>
</table></td>
<td valign=bottom width=556 bgcolor="#4c029c" height=96>
<table cellpadding="0" cellspacing="0" border=0 width=556 bgcolor="#4c029c" height=96>
<tr><td height=25 valign=bottom bgcolor="#ffffff" colspan=2 ><img src="top00003.gif" usemap="#F"></td></tr>
<tr valign=middle >
<td align=center valign=middle height="60" align=center>
<!-- <a href="/search/" target=_blank><img src="/img2/esearch.GIF" border=0 width=468 height=60></a> --><a href="http://www.ccw.com.cn/html/search/thememail/" target=_blank><img src="topbannh.gif" border=0 width=468 height=60></a>
</td>
<td align=center width=15%>
<table width=95%>
<tr><td><a href="mailto:center@ccw.com.cn?subject=%E6%88%91%E8%A6%81%E6%8A%95%E7%A8%BF:" target=_blank><font class=v13>我要投稿</a><br><a href="mailto:center@ccw.com.cn?subject=%E7%BC%96%E8%AF%BB%E5%BE%80%E6%9D%A5"><font class=v13>編讀往來</a><br><a href="javascript:AddBookMark('計算機世界網首頁')"><font class=v13>加入收藏</a></font></td></tr>
</table>
</td>
</tr>
<tr><td bgcolor="#ffffff" height=1 colspan=2 ></td></tr>
<tr><td bgcolor="#b4aafc" height=2 colspan=2 ></td></tr></table>
<map name="F">
<area href="http://www.ccw.com.cn/" shape="rect" coords="29, 3, 61, 18" target=_blank>
<area href="http://www.ccw.com.cn/news1/" shape="rect" coords="72, 3, 143, 18" target=_blank>
<area href="http://www.ccw.com.cn/center/" shape="rect" coords="155, 2, 216, 18" target=_blank>
<area href="http://www.ccw.com.cn/work/" shape="rect" coords="225, 2, 299, 18" target=_blank>
<area href="http://www.ccw.com.cn/search/" shape="rect" coords="310, 3, 364, 19" target=_blank>
<area href="http://www3.ccw.com.cn/" shape="rect" coords="372, 2, 412, 19" target=_blank>
<area href="http://www2.ccw.com.cn/" shape="rect" coords="424, 2, 550, 18" target=_blank></map>
</td></tr>
<tr><td colspan=2 bgcolor="#b4aafc">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td width=26% align=center><font class=v12>【2003年2月7日】 </font></td>
<td CLASS=V12> <a href="http://www.ccw.com.cn/center/topic.asp">專 題</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/tech.asp">技 術</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prod.asp">產 品</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/app.asp">應 用</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/net.asp">網 絡</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prog.asp">編 程</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/skill.asp">技 巧</a> </td>
</tr>
</table>
</td></tr>
</table>
<table align=center width=680>
<tr><td align=center><br><h2><font color='#0f3ccd'>Perl 語言全面編譯(四)</font></h2>
<b><a href="mailto:tanshuai@BIGFOOT.COM"><font color="#0000FF">天水-S.Tanshuai</font></a></b>
<br><hr size=1 width=660 color=#f46240></td></tr></table><br>
<table align=center width=620><tr><td class=a14><b><font size="4">第四節 PerlCC之Bytecode 編譯解析法</font></b></td></tr></table><table align=center width=620><tr><td class=a14>
Bytecode 是 PerlCC的另一編譯方法,必須在Perl5.6以后版本才有得支持。它的原理就好像Java一樣,它會把Perl文件編譯成二進制令人費解的亂碼文件,它是采用類似MD5這樣的反向加密編碼,幾乎不可能反編譯,和可執行程序一樣復雜,但是它不可以直接執行哦。想要執行它,必須用Perl解析器,就好像 Java 編譯后必須有Java解析器,否則就無法執行。我習慣成為編譯解析法,有的時候就說Just Like Java Progam!</td></tr></table><table align=center width=620><tr><td class=a14>
它的編譯方法也不難,但是竟然有很多人都不知道,我問過很多Perl前輩,他們也不大了解這一方法。而且很多我也從來見過誰寫過這樣的程序(難道我是國內第一個知道的嗎?:)</td></tr></table><table align=center width=620><tr><td class=a14>
使用方法:perlcc –b <程序名> </td></tr></table><table align=center width=620><tr><td class=a14>
編譯后它會輸出一個<程序名.plc>文件,你打開它看,定會吃驚。而且這種文件最小是180KB,比perlcc C語言轉換編譯多了很多。</td></tr></table><table align=center width=620><tr><td class=a14>
它的好處在于,一處編譯到處使用。但是對于CGI就不大好處理。所以還是建議在各個平臺進行編譯。</td></tr></table><table align=center width=620><tr><td class=a14>
例如我ByteCode編譯上節的abc.pl程序文件:</td></tr></table><table align=center width=620><tr><td class=a14>
輸入:</td></tr></table><table align=center width=620><tr><td class=a14>
perlcc –b abc.pl</td></tr></table><table align=center width=620><tr><td class=a14 bgcolor="#C0C0C0">
Perlcc –B 輸出</td></tr></table><table align=center width=620><tr><td class=a14>
----------------------------------------------------------------------------</td></tr></table><table align=center width=620><tr><td class=a14>
Compiling abc.pl:</td></tr></table><table align=center width=620><tr><td class=a14>
----------------------------------------------------------------------------</td></tr></table><table align=center width=620><tr><td class=a14>
Making Bytecode(abc.plc) for abc.pl!</td></tr></table><table align=center width=620><tr><td class=a14>
C:\perl\5.6.0\bin\MSWin32-x86\perl.exe -IC:/perl/5.6.0/lib/MSWin32-x86 -IC:/perl</td></tr></table><table align=center width=620><tr><td class=a14>
/5.6.0/lib -IC:/perl/site/5.6.0/lib/MSWin32-x86 -IC:/perl/site/5.6.0/lib -I. -MB</td></tr></table><table align=center width=620><tr><td class=a14>
::Stash -c abc.pl</td></tr></table><table align=center width=620><tr><td class=a14>
C:\perl\5.6.0\bin\MSWin32-x86\perl.exe -IC:/perl/5.6.0/lib/MSWin32-x86 -IC:/perl</td></tr></table><table align=center width=620><tr><td class=a14>
/5.6.0/lib -IC:/perl/site/5.6.0/lib/MSWin32-x86 -IC:/perl/site/5.6.0/lib -I. -MO</td></tr></table><table align=center width=620><tr><td class=a14>
=Bytecode,-umain,-uattributes,-uDB,-uWin32 abc.pl</td></tr></table><table align=center width=620><tr><td class=a14>
abc.pl syntax OK</td></tr></table><table align=center width=620><tr><td class=a14>
好了,然后perl abc.plc 就可以執行了。</td></tr></table><table align=center width=620><tr><td class=a14>
執行注意事項:</td></tr></table><table align=center width=620><tr><td class=a14>
使用Bytecode 編譯后的文件,你一般需要更名回原來的文件名,否則容易在運行程序后出現警告信息“Attempt to free unreferenced scalar.”雖然它對程序沒有本質影響,但是不美觀嘛,另一種解決方法就是使用 perl –X ,關閉所有警告消息,警告不等同與錯誤,所以一般情況下,某些警告是不必要的。</td></tr></table><table align=center width=620><tr><td class=a14>
同樣ByteCode 編譯程序可以被引用(require)但是不能調用(use),可以作為對象編程的對象。這是一個很靈活的東西,如果你希望你的模塊被大家使用,但是不想讓大家知道其中的操作,那么你就是用ByteCode,但是你的模塊將永遠不會被納入CPAN。這種方法就好像OCX控件。</td></tr></table><table align=center width=620><tr><td class=a14>
但是注意,但是使用某個模塊的時候,你必須保證使用該程序的機器上有這個模塊,最簡單的方法你可以把模塊一起復制使用,但是有些第三方程序模塊需要重新編譯,你如果不希望其它人操作模塊或者是看到引用的模塊,也可以使用Bytecode。但是注意,一定要用require方法調用加密模塊啊。這個世界總是這樣,總會有些遺憾的,這樣的話就不能用一些模塊和OOP。</td></tr></table><table align=center width=620><tr><td class=a14>
不知道你了解Python這個語言否?它Perl很相像,比Perl還有簡單呢。但是我認為很多東西都是抄Perl的,包括它得二進制編譯方法,就和Perl Bytecode沒有任何區別。反正大家也都知道PHP也是抄了Perl不少東西。</td></tr>
<tr><td class=a14>
<p align="right"><a href="http://www.ccw.com.cn/htm/app/aprog/01_4_11_6.asp"><font color="#0000ff">上一講
>></font></a> <a href="http://www.ccw.com.cn/htm/app/aprog/01_4_12_3.asp"><font color="#0000FF"><< 下一講</font></a></td></tr>
</table><br>
<table align=center width=620><tr><td align=right>(網頁編輯:<a href='mailto:app@ccw.com.cn'>徐向陽</a>)</td></tr></table><br>
<br><table align=center width=620><tr><td class=a14>相關文章</td></tr><tr><td><ul>
<li><a href='http://www.ccw.com.cn/htm/app/aprog/01_4_11_6.asp'>Perl 語言全面編譯(三)</a></li>
<li><a href='http://www.ccw.com.cn/htm/app/aprog/01_4_11_5.asp'>Perl 語言全面編譯(二)</a></li>
<li><a href='http://www.ccw.com.cn/htm/app/aprog/01_3_27_4.asp'>Perl 語言全面編譯</a></li>
<li><a href='http://www.ccw.com.cn/htm/app/aprog/001228_4.asp'>也談基于Web的Form多響應技術</a></li>
</ul></td></tr></table>
<table align=center width=620><tr><td align=right>
<form method=post action='/pub/subMail.asp' onsubmit='JavaScript: return chkField(this)'>
<INPUT type='hidden' name='rec' value='10372'>
您的姓名:<INPUT type="text" name=myName size=10>
您朋友的E-mail:<INPUT type="text" name=friendMail size=10>
<INPUT type="submit" value="推薦給好友">
</form>
</td></tr>
<tr><td align=right>
<b>[<a href="javascript:window.close()">關閉窗口</a>]</b>
</td></tr>
</table>
<script language="javascript">function chkField(fmObj)
{if (!fmObj.friendMail.value){
alert("請輸入您朋友的E-mail!");
fmObj.friendMail.focus();
return false;
}
return true;
}
</script>
<table align=center width=680>
<tr><td><hr size=1 width=660 color=#f46240></td></tr>
</table><br>
<p align=center>Copyright(C) ccw.com.cn,All rights reserved</p>
<p align=center><b>中國計算機世界出版服務公司版權所有</b></p><!-- This document saved from http://www.ccw.com.cn/htm/app/aprog/01_4_12_2.asp -->
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -