裸块的特点:裸块内用my声明的变量只在裸块内有效
Eg:
my $a = 10;
sub fun{
printf "%s\n",$a;
}
fun(); ##10
{
my $a =20;
sub naked_fun{
printf "%s\n",$a;
}
naked_fun(); #20
fun(); #10
}
naked_fun(); #20
fun(); #10
但是对没有用my声明的变量,没有这个效果
Eg:
my $a = 10;
sub fun{
printf "%s\n",$a;
}
fun(); ##10
{
$a =20; #和正常的改值语句相同
sub naked_fun{
printf "%s\n",$a;
}
naked_fun(); #20
fun(); #20
}
naked_fun(); #20
fun(); #20