thinking+in+perl

上传人:j7****6 文档编号:62239615 上传时间:2018-12-18 格式:PPT 页数:100 大小:3.04MB
返回 下载 相关 举报
thinking+in+perl_第1页
第1页 / 共100页
thinking+in+perl_第2页
第2页 / 共100页
thinking+in+perl_第3页
第3页 / 共100页
thinking+in+perl_第4页
第4页 / 共100页
thinking+in+perl_第5页
第5页 / 共100页
点击查看更多>>
资源描述

《thinking+in+perl》由会员分享,可在线阅读,更多相关《thinking+in+perl(100页珍藏版)》请在金锄头文库上搜索。

1、1,Thinking in Perl -Perl DBI,Charlie Cao (Cao, Xiaobing) CMB Ext. 78272,2,Contents,Overview Data Types Variables Common Predefined Variables Constants Reference Control Structures Terseness Regular Expression Subroutines Using Modules DBI (Database Interface) Convert DBLib to DBI (DBD),3,What is Per

2、l?,Perl is short for “ Practical Extraction and Report Language“ (Pathologically Eclectic Rubbish Lister) designed by Larry Wall (12, Dec. 1987). Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administ

3、ration, web development, network programming, GUI development, and more. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features are that its easy to use, supports both procedural and object-oriented (OO) programm

4、ing, has powerful built-in support for text processing, and has one of the worlds most impressive collections of third-party modules.,4,Running Perl programs,Windows (ActivePerl 5.10, Download): perl sample.pl sample.pl perl sample.pl perl -e “print hello world!“ Unix/Linux (Perl 5.8.0): perl sample

5、.pl chmod 0777 (a+x) sample.pl sample.pl (#!/export/opt/perl/5.8.0/bin/perl) perl sample.pl perl -e “print hello world!“,5,Perldoc command,perldoc perl Overview of Perl language perldoc module name (e.g DBI) help doc of the module perldoc f (subroutine name (e.g split) help doc of the subroutine,6,E

6、mulated IDE- Ultra Edit,7,Emulated IDE- Ultra Edit,8,Emulated IDE- Ultra Edit,9,Data Types,Scalar Integer 0 -40 255 61298040283768 61_298_040_283_768 Float 1.25 255.000 7.25e45 -6.5e24 -12e-24 Octal 047 49 (Dec) Hex 0x1f 31 (Dec) Binary 0b11111111 255 (Dec),10,Data Types,Scalar String Double quote:

7、$result = 14; print (“The value of $result is $result.n“) #The value of $result is 14.,11,Data Types,Scalar String Single quote: $text = This is two lines of text ; $text = “This is twonlines of textn“; Subroutines: q /Hello world/ # gets Hello world qq /Hello world/ # gets “Hello world” length($str

8、ing); substr(string, offset, length) uc/lc(string) join(expr, list) # $text = join(, lines); ltrim/rtrim(string),12,Data Types,Scalar String/Numeric conversion $string = “43“; $number = 28; $result = $string + $number; # $result = 71 $result = $string.$number; # $result = “4328“ $result = $string x

9、3; # $result = “434343“ $result = “hello“ * 5; # $result = 0 $result = “12a34“ +1; # $result = 13,13,Data Types,List Samples: (1,2,3) (1,2,3,) () (1 100) (1757) (5 1) (0,2 6,10,12) ($m $n) (0 $#array) (“fred”, “barney”, “betty”, “wilma”, “dino”) ($rocks0,$rocks1,$rocks2,$rocks3) = (“fred”, “barney”,

10、 “betty”, “wilma”, “dino”); rocks = (“fred”, “barney”, “betty”, “wilma”, “dino”); ($fred, $barney) = ($barney, $fred); copy = quarry; $abc=“00“,“01“,“10“,“11“; $var=$abc-11; Subroutines: QW qw(fred barney betty wilma dino) qw ! fred barney betty wilma dino ! qw # fred barney betty wilma dino # qw fr

11、ed barney betty wilma dino ($rocks0,$rocks1,$rocks2,$rocks3) = qw/talc mica feldspar quartz/; rocks = qw / bedrock slate lava /; ($fred, $barney) = qw ;,14,Data Types,List Subroutines: pop/push array = 59; $fred = pop(array); #$fred = 9,array =(5,6,7,8) $barney = pop array; #$barney = 8, array =(5,6

12、,7) pop array; #array =(5,6) push(array,0); #array = (5,6,0) push array,8; #array =(5,6,0,8) push array,110; #array others =qw/9 0 2 1 0 /; push array,others;,15,Data Types,List Subroutines: shift/unshift array = qw# dino fred barney #; $m = shift (array); #$m = “dino”, array = (“fred”, “barney”) $n

13、 = shift array; #$n = ”fred”, array =(“barney”) shift array; #array is empty $o = shift array; #$o = undef, array is still empty unshift(array,5); #array =(5) unshift array,4; #array = (4,5) others = 13; unshift array, others; #array =(1,2,3,4,5),16,Data Types,List Subroutines: reverse fred = 6 10;

14、barney = reverse (fred); #gets 10,9,8,7,6 sort rocks = qw/ bedrock slate rubble granite /; sorted = sort(rocks); #gets bedrock, granite, rubble, slate back = reverse sort rocks; #from slate to bedrock rocks = sort rocks; #gets sorted rocks numbers = sort 97 102; #gets 100,101,102,97,98,99 sort rocks

15、; #error, the subroutine must have a return value split $info = “Caine:Micheal:Actor:14,Leafy Drive”; personal = split(/:/,$info); #personal = (“Caine“, “Michael“, “Actor“, “14, Leafy Drive“);,17,Data Types,Scalar/List Context 42 + something #something must be a scalar sort something #something must

16、 be a list people = qw( fred barney betty ); $number = people; # $number = 3 sorted = sort people; #list context:barney , betty, fred $number = 42 + people; #scalar context:42+3, $number = 45 backwards = reverse qw / yabba dabba doo /; #gets doo, dabba, yabba $backwards = reverse qw/ yabba dabba doo /; #gets oodabbadabbay ro

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号