Or do I just need to fix the syntax.
That will be needed, yes. You should move the open, close and format statements outside the loop. You should ensure that you have alternate format strings with values. Here's an SSCCE to get you started using a subset of the form:
#!/usr/bin/env perl use strict; use warnings; my $report = print_query_results (); print "Here comes my report: \n$report\n"; exit; sub print_query_results { my @foo = ([9, 8, 7], [6, 5, 4]); my $blurb = 'Whatever'; my $report; my ($sql_id, $min_last_load_time, $buffer_gets); format REPORT = @|||||||||||||||@||||||||||||||||||||@||||||||||||||| 'SQL_ID', 'min_last_load_time','buffer_gets' @|||||||||||||||@||||||||||||||||||||@||||||||||||||| $sql_id, $min_last_load_time, $buffer_gets @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $blurb . open REPORT, '>', \$report; for my $aref (@foo) { ($sql_id, $min_last_load_time, $buffer_gets) = @$aref; write REPORT; } close REPORT; return $report; }
There are more modern ways of achieving the same end. While format is useful for the odd quick-and-dirty script here and there I wouldn't recommend spending large amounts of time or effort getting into the details. If you need this sort of thing often, consider something like Template as a better investment.
In reply to Re: I need outputting the results of a query in a formatted way to a scalar, so that I can email the results
by hippo
in thread I need outputting the results of a query in a formatted way to a scalar, so that I can email the results
by gandolf989
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |