in reply to Reference to a function
You should omit the parentheses, they try to call the sub before the reference is made. my $cref = \&getGlobalName;
I'm unclear whether you're asking about C scoping rules for variables outside a function definition's scope, operations on a reference passed as an argument, or for external access to a function's internal variables. I think you mean the latter.
In C/C++ you can safely "reach in" only for malloc'd (or new'd) store. A popular error is to return a reference to some auto variable within a function's definition block. By contrast, it is perfectly alright to return a reference to a lexical in perl. Reference counting keeps the value alive,
sub foo { my @stuff = @_; # do stuff to @stuff return \@stuff; }
After Compline,
Zaxo
|
|---|