for my $dbh ( @db_handles) { my ( $crud_cache, $crud_stuff_cache, $stuff_name_cache) = ({},{},{}); my @filter_foo_name; if ($do_some_filtering) { @filter_foo_name = ( \&filter_foo_name, { FILTER => $this } ); } my $f = mk_iterator( { DBH => $dbh, BIND => SQL_INTEGER }, \&get_foo, { WHERE_CLAUSE => $where{$dbname} }, \&get_wibble, \&get_stuff, \&get_crud, [ \&get_more_important_stuff, \&get_foo_wibble_id, \&get_bar_wibble_id, \&get_foo_name, @filter_foo_name, \&get_bar_name, \&get_foo_wibble_thingy_id, \&get_bar_wibble_thingy_id, \&get_foo_crud_id, \&get_bar_crud_id, \&get_foo_crud_name, { CACHE => $crud_cache }, \&get_bar_crud_name, { CACHE => $crud_cache }, \&get_foo_crud_stuff, { CACHE => $crud_stuff_cache }, \&get_bar_crud_stuff, { CACHE => $crud_stuff_cache }, ], [ \&get_stuff_name, \&get_stuff_type, \&get_stuff_this_and_that, \&get_stuff_this_name, { OUTER => 1, BIND => SQL_VARCHAR, CACHE => $stuff_name_cache }, \&get_stuff_that_name, { OUTER => 1, BIND => SQL_VARCHAR, CACHE => $stuff_name_cache }, \&get_foo_crud_stuff, { OUTER => 1, CACHE => $crud_stuff_cache }, \&get_bar_crud_stuff, { OUTER => 1, CACHE => $crud_stuff_cache }, ], ); while ( my $row = $f->() ) { # do stuff w/$row which is a hashref # w/all the keys from the SELECT array refs (see # sql_iterator() example below). # # Update: Actually, since there are array refs # in the iterator constructor, the actual href here # will contain all of the keys from the first # four iterators, and for each of those values, # it will iterate through values containing # keys from the first array ref, then through # values containing keys from the second array ref print join(",", $@row{qw(FOO_WIBBLE_ID FOO_NAME BAR_WIBBLE_ID BAR_NAME ETC ETC)}), "\n"; } } #### sub get_foo_wibble_id { sql_iterator( SQL => "select WIBBLE_ID\n". "from WIBBLE_TABLE\n". "where STUFF_ID = ?\n". "and IMPORTANT_ID = ?\n", SELECT => ['FOO_WIBBLE_ID'], ARGS => [qw(STUFF_ID FOO_THINGY_ID)], @_, ) } sub get_bar_wibble_id { get_foo_wibble_id( SELECT => ['BAR_WIBBLE_ID'], ARGS => [qw(STUFF_ID BAR_THINGY_ID)], @_, ) }