2011年10月21日 星期五

深入了解local標籤的意義

$x = 10;
first();
sub first {
    local ($x) = "zen";      # $x is still global, and has a new value
    print "in first:",$x,"\n";#print "zen"
    second();
}


sub second {
    print "in second:",$x,"\n";   # Prints "zen", the current value of the global $x
}


print $x,"\n";#Prints 10
#NOTE:In other words, local makes a global variable's new value temporary;

沒有留言:

張貼留言