in reply to Several stupid questions about subs
1) Is this were "my" comes in? What about "local?" What's the difference? I understand local went out with the goto statement. True?
To explain the differences, there would have to similarities.
my creates a lexically scoped variable.
local temporarily saves a package variable, array element or hash element. The previous value of the variable will be restored when the current scope is exited.
2) How do I return a value from a sub to main, if Perl doesn't have a return statement?
By using the return statement or by evaluating the value to return as the last statement of the sub.
sub f { ...; return $x + 1 } sub f { ...; $x + 1 }
|
|---|