for (keys %{$self->{SQL}}) { my $closure = $_; $self->{$_} = $self->{DBO}->prepare($self->{SQL}->{$_}); $self->{"f$_"} = sub { my $self = shift; my @res; $self->{ $closure }->execute(@_); while (my $dbrow = $self->{ $closure }->fetchrow_hashref()) { push @res, \$dbrow; } return \@res; }; } #### undef %h; for( qw[ the quick brown fox ] ){ $h{ $_ } = sub { print "$_"; }; }; pp \%h; do { my $a = { brown => sub { "???" }, fox => 'fix', quick => 'fix', the => 'fix' }; $a->{fox} = $a->{brown}; $a->{quick} = $a->{brown}; $a->{the} = $a->{brown}; $a; } $_='joe'; for my $key ( keys %h ) { $h{ $key }->(); };; joe joe joe joe #### undef %h; for( qw[ the quick brown fox ] ){ my $closure = $_; $h{ $_ } = sub { print $closure; }; }; pp \%h; { brown => sub { "???" }, fox => sub { "???" }, quick => sub { "???" }, the => sub { "???" }, } $_='joe'; for my $key ( keys %h ) { $h{ $key }->(); };; the fox brown quick