Short answer: the first array holds the names, the second holds the values.
#!/usr/bin/perl
use 5.010; # sorry,
use feature ':5.10'; # testing out 5.10 features
use strict;
use warnings;
use List::Util 'max';
use B;
sub dumpem;
{
my $closed = 3; # sub1 closes around this var
sub sub1 {
state $state_in = 5; # a state var in sub1
my $my_in = 6; # a my var in sub1
my %hash = (a=>2); # a hash in sub1
dumpem "sub1";
$my_in +
$closed; # use it so it's not optimized away
}
}
sub B2str {
my $o = shift;
return $o unless ref $o;
my $r = "$o";
given(B::class($o)) {
when ('SPECIAL') { $r = $B::specialsv_name[$$o] }
when (['PVIV','IV']) { $r = $o->IVX }
when (['PVNV','PV']) { continue if !defined($r = $o->PV); $r =
+ "'$r'" }
when (['PVNV','NV']) { $r = $o->NVX }
when (['HV','AV']) {
my ($open, $close, @sep) = split /\|/, /AV/ ? '(|)|,' : '{
+|}| =>|,';
my @in = map B2str($_), $o->ARRAY;
$in[$_] .= ($_!=$#in?$sep[$_%@sep]:'') for 0..$#in;
$r = join ' ', $open, @in, $close;
}
when ('NULL') { $r = ref $o }
default { $r = "$o" }
}
$r;
}
sub dumpem {
my $in = shift;
my ($nam, $val) = B::svref_2object(\&sub1)->PADLIST->ARRAY;
s/^'//, s/'$// for my @names = map B2str($_), $nam->ARRAY;
my @vals = map B2str($_), $val->ARRAY;
my $l = max map length, @names;
$_ = sprintf "%-*s", $l, $_ for @names;
say for "", "In $in", map " $names[$_] = $vals[$_];", 0..$#names;
}
dumpem "main before sub1";
sub1 7, 11, 13; # 7,11,13 just demonstrates where @_ is stored
dumpem "main after sub1";
__END__
Output:
In main before sub1
&PL_sv_undef = ( );
$state_in = B::NULL;
$my_in = B::NULL;
%hash = { };
&PL_sv_undef = B::NULL;
&PL_sv_undef = B::NULL;
$closed = 3;
&PL_sv_undef = B::NULL;
In sub1
&PL_sv_undef = ( 7, 11, 13 );
$state_in = 5;
$my_in = 6;
%hash = { a => 2 };
&PL_sv_undef = B::NULL;
&PL_sv_undef = B::NULL;
$closed = 3;
&PL_sv_undef = B::NULL;
In main after sub1
&PL_sv_undef = ( );
$state_in = 5;
$my_in = 6;
%hash = { };
&PL_sv_undef = B::NULL;
&PL_sv_undef = B::NULL;
$closed = 3;
&PL_sv_undef = 9;
Some interesting things: '@_' is stored in the first unnamed slot. The last unnamed slot is a temp var for the return result ($my_in + $closed) == 9.
Also see: Re^7: private recursive subroutines. (Wrote this node before just now finding that -- important note is that PADLIST has a stack of values, but just one set of names.)