in reply to Difference my and local
Hello
my:
your subroutine needs temporary variables. You shouldn't use global variables, because another subroutine might also use the same variables.
local:
All subroutines called from the context of a local variable can access that variable.
$a='one'; $b='two'; sub1(); sub sub1 { local $a = 'three'; my $b = 'four'; sub2(); } sub sub2 { print "\$a: $a\n"; print "\$b: $b\n"; }
Output
$a: three $b: two
|
|---|