in reply to Nested references
Not directly (maybe using PadWalker or some such), unless you make it available to the outside, e.g. by returning it as an (optional) second value:
#!/usr/bin/perl -l use strict; use warnings; my $code_ref = sub { my $array_ref; my $nested_code_ref = sub { my @array = ("one","two","three"); $array_ref = \@array; }; $nested_code_ref->(); return wantarray ? ($array_ref, $nested_code_ref) : $array_ref; }; print $code_ref->()->[0]; print $code_ref->()->[1]; print( ( $code_ref->() )[1]->()[2] ); __END__ $ ./837730.pl one two three
We might be able to give a more useful answer, if you could explain your intention — from the question it's not really clear whether you want achieve or avoid that $nested_code_ref be accessible from the outside...
|
|---|