http://qs321.pair.com?node_id=1166301


in reply to naming anonymous subroutines inner variables

For the anon subroutine to access each key at its | the subroutine's runtime, it needs to create a closure over a lexical variable (not, of course, access the global $_ variable) when the subroutine is created. Try something like (untested):

for my $k (keys %{$self->{SQL}}) { ...; $self->{"f$k"} = sub { ...; $self->{$k}->execute(@_); while (my $dbrow = $self->{$k}->fetchrow_ +hashref()) { ...; } return ...; }; }
Basically, all the  $_ scalars become  $k scalars.


Give a man a fish:  <%-{-{-{-<