国立中央大学电算中心陈庆彦.ppt
《国立中央大学电算中心陈庆彦.ppt》由会员分享,可在线阅读,更多相关《国立中央大学电算中心陈庆彦.ppt(71页珍藏版)》请在三一办公上搜索。
1、2023/9/4,國立中央大學電算中心 陳慶彥,1,CGI程式設計(for UNIX Perl),2023/9/4,國立中央大學電算中心 陳慶彥,2,主題,CGI 及其環境簡介 Perl 程式設計應用系統實作 公佈欄,2023/9/4,國立中央大學電算中心 陳慶彥,3,CGI 及其環境簡介,Internet,後端資料庫,CGI程式,前端瀏覽器,2023/9/4,國立中央大學電算中心 陳慶彥,4,CGI 及其環境簡介(cont),為什麼我的 HTML page/form 需要用 script因為有的時候您需要在 HTML 文件中使用動態資料(非固定不變的資料)CGI 各代表什麼?Common 向
2、您確保 CGI 可以使用多種程式語言並和多種 不同的系統互動Gateway 提示您 CGI 的力量不在於它本身所做的事,而 在於它提供了連結其他系統的潛力Interface 只是表示 CGI 對如何善用其特性提供了明確的 界定換句話說,您可以設計程式來適當利用這 個介面。,2023/9/4,國立中央大學電算中心 陳慶彥,5,CGI 及其環境簡介(cont),CGI程式相關的環境變數,2023/9/4,國立中央大學電算中心 陳慶彥,6,CGI 及其環境簡介(cont),Perl是什麼東西呢?它是Practical Extraction Report Language等字的縮寫,是一種能掃視任意文
3、字檔,並且能從中取出資訊製成報表的解譯語言(Interpreter)。Perl的作者Larry Wall說過一句話:Perl是懶人用的工具。如果Perl不是比其它語言更好更簡單更容易上手,恐怕很少人願意去學習新的程式語言。,2023/9/4,國立中央大學電算中心 陳慶彥,7,CGI 及其環境簡介(cont),Perl的特性Perl有非常傑出的文字處理能力,能輕易地產生HTML文件,尤其它具有完整的Regular Expression語法,使得在C語言看來必需要寫一大串程式碼的功能,Perl幾行就解決了。Perl是一種直譯式語言,因此可以避免在各種不同系統上,還需要重新編譯的麻煩。Perl的檢查
4、旗標(-T)可以保護你的Web Server,避免被未經授權的client破壞。,2023/9/4,國立中央大學電算中心 陳慶彥,8,CGI 及其環境簡介(cont),哪些平台上有 Perl?要到哪裡去找?,這套原始碼完全不需任何移植工作便可輕易地在絕大多數的 Unix系統(Perl的原生系統),以及 Plan 9、VMS、QNX、OS/2,和 Amiga上編譯安裝完成。適合 32 位元的微軟系統和蘋果系統、以執行檔形式發行的 Perl各可在 http:/,2023/9/4,國立中央大學電算中心 陳慶彥,9,CGI 及其環境簡介(cont),Perl的相關資料要上哪兒找?,man perl p
5、erldoc perl http:/,2023/9/4,國立中央大學電算中心 陳慶彥,10,Perl程式設計-執行環境,server 通常是設定成去執行放在 cgi-bin 目錄底下的 CGI 程式。不過,server 管理者同時也可以在設定檔中設定 aliases,讓所有含某些副檔名(如.cgi、.pl)的 scripts 都能執行 AllowOverride None Options ExecCGI Options Indexes Includes ExecCGI AllowOverride None order allow,deny 什麼是檔案使用權限?怎樣改?,2023/9/4,國立中
6、央大學電算中心 陳慶彥,11,Perl程式設計-Lab 1.您的第一個程式,選擇編輯器 vi,joe,ee,pe2或是在client端將編輯好了的檔案上傳到server您的第一個程式hello.cgi#!/usr/bin/perl print“hello world!n”;Chmod 755 hello.cgi執行hello.cgi,2023/9/4,國立中央大學電算中心 陳慶彥,12,Perl程式設計-資料型態,Scalar:純量變數是Perl裡最基本的一種資料型態,它可以代表一個字元、字串、整數、甚至浮點數,而Perl把它們都看成是一樣的!Scalar Array:純量陣列,陣列內的每一個
7、元素都是Scalar variableHash Array(Associative Array):雜湊陣列也叫做相關陣列,它和一般陣列沒什麼不同,差別只是在它的索引值用的是字串,而非一般陣列所用的整數值References(Pointer):Perl 5新增了參考指標的資料型態使Perl和C一樣可借由指標建立一些複雜的資料結構。,2023/9/4,國立中央大學電算中心 陳慶彥,13,Perl程式設計-資料型態(cont),Scalar:字串運算子,2023/9/4,國立中央大學電算中心 陳慶彥,14,Perl程式設計-資料型態(cont),Scalar:字串運算子,2023/9/4,國立中央大
8、學電算中心 陳慶彥,15,Perl程式設計-資料型態(cont),Scalar:數值運算子,2023/9/4,國立中央大學電算中心 陳慶彥,16,Perl程式設計-資料型態(cont),Scalar:數值運算子,2023/9/4,國立中央大學電算中心 陳慶彥,17,Perl程式設計-資料型態(cont),Scalar:數值運算子,2023/9/4,國立中央大學電算中心 陳慶彥,18,Perl程式設計-資料型態(cont)-Lab 2,Lab2.Stg1.cgi#!/usr/bin/perl$name=Eric C.Herrmann;print The owner of this program
9、 is$namen;$firstName=Eric;$middleInitial=C.;$lastName=Herrmann;print The owner of this program is$firstName$middleInitial;print$lastNamen;$fName=Eric;$mInitial=C.;$lName=Herrmann;print The owner of this program is$fName$mInitial$lNamen;,2023/9/4,國立中央大學電算中心 陳慶彥,19,Perl程式設計-資料型態(cont),2023/9/4,國立中央大學電
10、算中心 陳慶彥,20,Perl程式設計-資料型態(cont)-Lab 3,Lab3.value1.cgi#!/usr/bin/perl$integerValue=10;$floatingPointValue=11.43;$scientificValue=42.03E-04;$nationalDebt=6_000_000_000_000;$divisionValue=23/7;$hexValue=0 x0F3;$octalValue=037;$itotal=$integerValue+$hexValue;$ftotal=$floatingPointValue+$integerValue;$dto
11、tal=$divisionValue+$octalValue;,print Integer t$integerValuen;print Floating Point t”;Print“$floatingPointValuen;print Scientific t$scientificValuen;print National Debt t$nationalDebtn;print Division t$divisionValuen;print Hex tt$hexValuen;print Octal tt$octalValuen;print nn;print itotal=$itotaln;pr
12、int ftotal=$ftotaln;print dtotal=$dtotaln;,2023/9/4,國立中央大學電算中心 陳慶彥,21,Perl程式設計-資料型態-Lab 3(cont),2023/9/4,國立中央大學電算中心 陳慶彥,22,Perl程式設計-資料型態(cont),Scalar Array:,純量陣列,陣列內的每一個元素都是Scalar variable。宣告及使用方式如下:#純量陣列以 開頭。my array;my array=qw(a b c d);#qw 函數會將其後的每個元素用逗點隔開,效果就像下面這行。my array=(a,b,c,d);,2023/9/4,國立
13、中央大學電算中心 陳慶彥,23,Perl程式設計-資料型態(cont),Scalar Array:,#當然你也可以一個個元素宣告,下面就是存取每一個元素的方法。#因為陣列中的每一個元素都是純量變數,所以要以$開頭,#剛開始容易搞混,請注意。$array0=a;$array1=b;$array2=c;$array3=d;#使用for loop印出陣列內每個元素的值。for($i=0;$i=$#array;$i+)print$array$in;,2023/9/4,國立中央大學電算中心 陳慶彥,24,Perl程式設計-資料型態(cont)-Lab4,Lab 4 scalearray1.cgi#!/u
14、sr/bin/perl FamilyName=(Steven,Michael,Herrmann);print$FamilyName0;print$FamilyName1;print$FamilyName2;print nn;print$FamilyName0$FamilyName1$FamilyName2n;,2023/9/4,國立中央大學電算中心 陳慶彥,25,Perl程式設計-資料型態(cont)-Lab5,Lab 5 scalearray2.cgi(Mixed Data Assigned to Array Cells),#!/usr/bin/perl$cellIndex=0;$mixed
15、Data$cellIndex=mixedData;$mixedData2=876;$mixedData6=The last cell;$mixedData4=3.41467;foreach$value(mixedData),print Cell number$cellIndex=$value n;$cellIndex+;print nn;print The last cell of the array mixedData is$#mixedData;print nn;,2023/9/4,國立中央大學電算中心 陳慶彥,26,Perl程式設計-資料型態-Lab5(cont),2023/9/4,國立
16、中央大學電算中心 陳慶彥,27,Perl程式設計-資料型態(cont),Hash Array(Associative Array),#相關陣列是以%符號開頭的。my%hash;my%hash=(i1=aaa,i2=bbb,i3=ccc);$hashi1=aaa;$hashi2=bbb;$hashi3=ccc;,2023/9/4,國立中央大學電算中心 陳慶彥,28,Perl程式設計-資料型態(cont)-Lab6,#!/usr/bin/perlprint nn;%priceList=(Hackamore=28.92,English Bridle=36.31,Western Saddle=124.
17、00,Hunt Seat Saddle=178.01,Jumping Saddle=205.87,Leather Halter=24.56,);,printAA(%priceList);print You could print a hash cell like this$priceListWestern Saddlen;%priceList=(1358=28.92,1359=36.31,1965=124.00,1966=178.01,1977=205.87,1357=24.56,);,Lab 6 hasharray.cgi,2023/9/4,國立中央大學電算中心 陳慶彥,29,Perl程式設
18、計-資料型態-Lab6(cont),print Or like this$priceList1965 nn;printAA(%priceList);sub printAA my%myPriceList=_;foreach$key(keys(%myPriceList)print The price of item$key is$priceList$keyn;print nn;,Lab 6 hasharray.cgi(cont),2023/9/4,國立中央大學電算中心 陳慶彥,30,Perl程式設計-資料型態-Lab6(cont),2023/9/4,國立中央大學電算中心 陳慶彥,31,Perl程式
19、設計-資料型態(cont),References(Pointer),如何取得變數的位址?$scalarRef=$scalarVar;$arrayRef=arrayVar;$hashRef=%hashVar;$funcRef=,2023/9/4,國立中央大學電算中心 陳慶彥,32,Perl程式設計-資料型態(cont),References(Pointer),如何使用指標?print$scalarRef;print$arrayRef;print$hashRef-$key;,2023/9/4,國立中央大學電算中心 陳慶彥,33,Perl程式設計-資料型態(cont)-Lab7,#!/usr/bin
20、/perl$hashRef=a=aa,b=bb,c=cc;print$hashRef-at$hashRef-bt$hashRef-cn;my%hashRef1=(a=aa,b=bb,c=cc);print$hashRef1at$hashRef1bt$hashRef1cn;,Lab 7 pointer.cgi,2023/9/4,國立中央大學電算中心 陳慶彥,34,Perl程式設計-控制敘述,條件控制敘述(Conditional Control Statements),if(Expression)Code Segment if(Expression)Code Segment else Code S
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 国立中央大学 电算 中心 陈庆彦

链接地址:https://www.31ppt.com/p-5915685.html