## 4-1 ?芥暩

﹍郎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 ┮﹚竡Ы场跑计ㄤΤ絛瞅ㄧ计セōぃパㄧ计㊣ㄤㄧ计
• パ local ┮﹚竡Ы场跑计ㄤΤ絛瞅ㄧ计セōパㄧ计㊣ㄤㄧ计
τē埃獶Τ疭惠―玥и常ㄏノ my ㄓ﹚竡Ы场跑计

穨

Perl