Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://724065]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found