in reply to Only last record is written to the output file instead of all records
If you work with CSV files, you can use a dedicated module.
For example Text::CSV, Text::CSV_XS, DBD::AnyData or DBD::CSV
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # The default is to treat the first line # of the file as the list of column names # If you just want to select the women $dbh->func( 'people', 'CSV', '/home/user1/file.csv', { sql => "SELECT name FROM people WHERE genre='F'" }, 'ad_import' +); # Print the result as a HTML table print $dbh->func( 'people', 'HTMLtable', 'ad_export' ); # or save it in a file $dbh->func( 'people', 'HTMLtable', '/home/user/mytab1.html', 'ad_expor +t' );
OUTPUT: <table bgcolor="white" border="1"> <tr bgcolor="#c0c0c0"><th>name</th></tr> <tr><td>Kathy</td></tr> <tr><td>Stella</td></tr> <tr><td>Katherine</td></tr> </table>
hth,
PooLpi
|
|---|