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):
Basically, all the $_ scalars become $k scalars.for my $k (keys %{$self->{SQL}}) { ...; $self->{"f$k"} = sub { ...; $self->{$k}->execute(@_); while (my $dbrow = $self->{$k}->fetchrow_ +hashref()) { ...; } return ...; }; }
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: naming anonymous subroutines inner variables
by writch (Sexton) on Jun 22, 2016 at 20:29 UTC | |
by zwon (Abbot) on Jun 22, 2016 at 21:08 UTC |
In Section
Seekers of Perl Wisdom