For example, to quickly display the results of a query, you can
write:
$sth = $dbh->prepare( "
SELECT name, mapref, location
FROM megaliths
" );
$sth->execute( );
$rows = $sth->dump_results( );
which would display the following results:
'Balbirnie', 'NO 285 029', 'Balbirnie Park, Markinch, Fife'
'Castlerigg', 'NY 291 236', 'Near Keswick, Cumbria, England'
'Sunhoney', 'NJ 716 058', 'Near Insch, Aberdeenshire'
'Avebury', 'SU 103 700', 'Avebury, Wiltshire, England'
4 rows
You can customize the way in which this output is formatted by
specifying the maximum length of each field within the row, the
characters separating each field within the row, and the characters
separating each row. You can also supply a Perl filehandle to which
the output is written.
The default settings for these parameters are:
1: Maximum Field Length - 35
2: Line Separator - "\n"
3: Field Separator - ","
4: Output file handle - STDOUT
Therefore, to generate output with 80 character fields separated by
colons to a file, you can write:
### Prepare and execute the query
$sth = $dbh->prepare( "
SELECT name, location, mapref
FROM megaliths
" );
$sth->execute( );
### Open the output file
open FILE, ">results.lis" or die "Can't open results.lis: $!";
### Dump the formatted results to the file
$rows = $sth->dump_results( 80, '\n', ':', \*FILE );
### Close the output file
close FILE or die "Error closing result file: $!\n";