Presentation is loading. Please wait.

Presentation is loading. Please wait.

生物資訊程式語言應用 Part 3 Perl Language.

Similar presentations


Presentation on theme: "生物資訊程式語言應用 Part 3 Perl Language."— Presentation transcript:

1 生物資訊程式語言應用 Part 3 Perl Language

2 Outline Introduction. Installation. Background knowledge in Perl.
Data type. Control structure. Regular expression. Overall practice.

3 Introduction Perl is free software. Larry Wall (He is a linguist).
The history of Perl language. 1987- Perl 1.0. Perl 5 (contain OOP). OOP (object oriented programming) 物件導向程式語言 Perl – support unicode. 2003 – Perl 6. Now. Characteristic. The script language base on C language (具跨平台的特性).

4 Installation Perl is the default language in any distribution of Linux. Perl can be executed and worked by the ActivePerl package in windows platform. How to edit Perl program? Notepad in windows, UltraEdit and any text editor.

5 Installation cont. Practice. Download ActivePerl software file.
Install ActivePerl.

6 Background knowledge Data type in Perl. Control structure in Perl.
Regular expression in Perl.

7 Data type in Perl Like English Scalar (純量變數) – 比喻單件事物. 字串與數字間的轉換
數字常數 $x = 5; 字串常數 $y = “Hello” ; The special expression of Perl. Print “Hello” . ”World” ; (Hello World). Print “Hello” * 2 ; (HelloHello). 字串與數字間的轉換 $x = 123; $y = “456”; Print $x + $y ; (數字) Print $x . $y ; (字串)

8 Data type in Perl cont. Practice. Using scalar. Special expression.
字串與數字間的轉換.

9 Data type in Perl cont. Array (陣列). The definition of Array in Perl.
@student=(" "," ",” ”); $student[0] =" “; $student[1] =“ “; $student[2] =“ ”; Array 單數的取用. print $student[0],"\n"; print "$student[1]\n"; print $student[2]."\n"; Array 複數的取用. (全部一起print出來) 以單數取用方式print出複數資料 (in control structure chapter).

10 Data type in Perl cont. Practice. Using array (definition). 單數取用.
複數取用.

11 Data type in Perl cont. Hash (雜湊). $純量 = 單一 = 單數 @陣列 = 串列 = 複數
%雜湊 = 串列 = 複數 定義陣列 = 類似ip @student=(" "," ",” ”); 定義雜湊 = 類似dns %students = ("Peter"=>" " , "Mary"=>" " , "Cathy"=>" ");

12 Data type in Perl cont. Hash (雜湊). 定義雜湊 = 類似dns Hash 單數的取用.
%students = ("Peter"=>" " , "Mary"=>" " , "Cathy"=>" "); Hash 單數的取用. print $students{"Peter"},"\n"; print $students{"Mary"},"\n"; print $students{"Cathy"},"\n"; Hash 複數的取用. print %students,"\n"; 以單數取用方式print出複數資料 (in control structure chapter).

13 Data type in Perl cont. Practice. Using hash (definition). 單數取用. 複數取用.

14 Control structure in Perl
If statement (陳述式). For loop (迴圏). Foreach loop (迴圏). While loop (迴圏).

15 Control structure in Perl cont.
If statement (陳述式). If 條件判斷 If 條件成立則執行 若If 條件不成立則執行 (else statement可有可無)

16 Control structure in Perl cont.
Practice. If statement. If - else statement.

17 Control structure in Perl cont.
For loop (迴圏). $#array : 取得array的大小 $i++ : 等同於 $i = $i + 1; $sum += $i : 等同於 $sum = $sum + $i;

18 Control structure in Perl cont.
Practice. For loop 迴圏. 以array單數取用方式print出array複數資料. 以hash單數取用方式print出hash複數資料.

19 Control structure in Perl cont.
Foreach loop (迴圏). Like for loop. For loop Foreach loop

20 Control structure in Perl cont.
Practice. Foreach loop (迴圏). 以array單數取用方式print出array複數資料. 以hash單數取用方式print出hash複數資料.

21 Control structure in Perl cont.
While loop (迴圏). While 判斷式

22 Control structure in Perl cont.
Practice. While loop (迴圏). 1+2+…+100.

23 Regular expression in Perl
樣式 (pattern) 的表達. 繫結符號 =~. =~可用來將右邊的樣式比對左邊的字串純量,成功 傳回1,失敗傳回0. 表否定則可改用!~ 通常搭配判斷式使用.

24 Regular expression in Perl cont.
比對. $` : 代表字串中比對成功之前的部分. $& : 代表字串中比對成功的部分. $‘ : 代表字串中比對成功之後的部分.

25 Regular expression in Perl cont.
字元取代. $var =~ tr/xxx/yyy/ 把變數 $var 內的 xxx 字元都逐一代換成 yyy 字元 字串取代. $var =~ s/xxx/yyy/ 把變數 $var 內的第一個 xxx 子字串整個代換成 yyy 子字串 $var =~ s/xxx/yyy/ig I : 忽略大小寫 g : 取代 $var 字串內所有符合的子字串

26 Regular expression in Perl cont.
Practice. 比對. 字元取代. 字串取代.


Download ppt "生物資訊程式語言應用 Part 3 Perl Language."

Similar presentations


Ads by Google