Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Only last record is written to the output file instead of all records

by poolpi (Hermit)
on Nov 17, 2008 at 15:35 UTC ( #724065=note: print w/replies, xml ) Need Help??


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

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://724065]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2017-12-15 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (443 votes). Check out past polls.

    Notices?