4-1 ?芥暩

埃ずㄧ计ぇ﹚竡 Perl ㄧ计ㄒ

﹍郎tsub1.plη︹跋办ㄢī
sub printVariable0 {
	print("X is equal to 10.\n");
}

&printVariable0;

ㄒいи﹚竡ㄧ计 printVariable0礛㊣ㄧ计棵辊

X is equal to 10. ㄧ计﹚竡ㄧ计㊣玡┪⊿Τ﹚砏﹚尺ㄓ逼ゲ斗猔種琌㊣ㄧ计﹚璶ㄧ计嘿ぇ玡&Perl ㄧ计や穿患癹㊣Recursive Calls传杠弧ㄧ计㊣ㄤセō

箇砞薄猵┮Τ Perl 跑计常琌办跑计Global Variables┮ㄧ计いまノㄤ跑计璶㊣ㄧ计玡跑计竒砆﹚竡ㄒ

﹍郎tsub2.plη︹跋办ㄢī
sub printVariable0 {
	print("X is equal to $X.\n");
}

$X = 20;
&printVariable0;

瓃祘Α絏い$X ㄧ计㊣玡砆﹚竡 20礛иㄧ计い跑计 $X挡狦

X is equal to 20. ㄧ计ずまノ办跑计ぃ琌瞶稱甧硑Θ埃岿螟ゑ耕快猭玥ㄏㄧ计Τま计Argumentsи盢ぃ跑计癳ㄧ计ㄓ秈︽笲衡Perl ㄧ计ず﹚ま计琌@_皚иノ皚ㄓ弄癳ㄧ计跑计ㄒㄧ计 printArgument 肚跑计计㎝Ч俱祘Α絏tsub3.pl

﹍郎tsub3.plη︹跋办ㄢī
&printArgument(@ARGV);
sub printArgument {
	my $count=@_;
	print("$count input argument(s): ");
	for ($i=0; $i<$count; $i++) {
		print("$_[$i] ");
	}
}

瓃祘Α絏い@_ 琌皚ウ材じ琌 $_[0]材じ琌 $_[1]ㄌ摸崩璝よΑ磅︽瓃祘Α

perl tsub3.pl 3 5 go test

玥癟

4 input argument(s): 3 5 go test 跑计 @_ 癸ㄧ计ㄓ弧琌Ы场跑计Local Variable璝ㄧ计﹚竡ぇΤ办跑计 @_玥秈ㄧ计办跑计 @_ 穦砆玂痙癬ㄓ┮Τ癸跑计 @_ 穦パЫ场跑计 @_ ┮ㄧ计挡Ы场跑计 @_ ア办跑计瞷確ㄤ

ㄆ龟и Perl ㄧ计い﹚竡ㄧ计Ы场跑计ㄓㄏ眔祘Α絏罙秆ㄒ

sub addTwoNumber { my($a, $b); # ﹚竡 $a ㎝ $b Ы场跑计 ($a, $b) = @_; # 砞﹚ $a ㎝ $b だ单肚跑计 return($a + $b); # 肚ㄢ计挡狦 } 瓃祘Α絏いиㄏノ my ㄓ﹚竡 $a ㎝ $b Ы场跑计砞﹚ $a ㎝ $b だ单肚跑计程琵ㄧ计肚 $a ㎝ $b 挡狦瓃ㄧ计い玡ㄢㄖΘ my($a, $b) = @_;

иノ local  my ㄓ﹚竡Ы场跑计ㄤΤ絛瞅Scope菠Τ畉钵弧

τē埃獶Τ疭惠―玥и常ㄏノ my ㄓ﹚竡Ы场跑计

穨
叫糶 Perl 祘Α浪琩ヘ玡ヘ魁┮Τ郎嘿┪ヘ魁嘿┮Τぃ才 DOS 8.3 郎砏郎┪ヘ魁嘿祘Αゲ斗患癹よΑㄓ浪琩┮Τ郎のヘ魁嘿1994掸瓣璶р UNIX 祇甶 MATLAB 祘Α絏锣 PC キ讽穨╰参琌 Windows 3.1磷郎┮盿ㄓ贺耑и碞盽璶絋粄┮Τ郎のヘ魁嘿常才 DOS 郎 8.3 Α砏讽掸ㄏノ Perl 祘ΑㄓЧΘ硂ン硂琌掸┮糶材 Perl 祘Α


Perl