sub dumpResultsToFile { my ( $query ) = @_; # Prepare and execute the query my $sth = $dbh->prepare( $query ); $sth->execute(); # Open the output file open FILE, ">results.txt" or die "Can't open results output file: $!"; # Dump the formatted results to the file $sth->dump_results( 80, "\n", ", ", \*FILE ); # Close the output file close FILE or die "Error closing result file: $!\n"; }