sub get_category_loop { return [ map { $_->{subject_loop} = get_subject_loop( delete $_->{category_id} ); # delete returns the value that was in the hash $_ } @{ $dbh->selectall_arrayref(sql_category(), {Slice => {}}) } ]; } sub get_subject_loop { my $category_id = shift; my $sth = $dbh->prepare_cached( sql_subject() ); $sth->execute($category_id); return $sth->fetchall_arrayref({}); } sub sql_category { return q{ SELECT category_id, category_name FROM category ORDER BY category_id }; } sub sql_subject { return q{ SELECT subject_id, subject_name FROM subject WHERE category_id = ? ORDER BY subject_name }; }