CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Tejas] Merging the data in two files using a hash: Edit Log



FishMonger
Veteran / Moderator

Sep 3, 2014, 8:20 AM


Views: 41751
Re: [Tejas] Merging the data in two files using a hash


Code
#!/usr/bin/perl 

use strict;
use warnings;
use DBI;
use DBD::CSV;
use Data::Dumper;

# connect to "csv database" using default parameters
my $dbh = DBI->connect("DBI:CSV:") or die $DBI::errstr;

# prepare and execute select statement to fetch 1 row
my $sth = $dbh->prepare("select * from file1.csv limit 1") or die $dbh->errstr();
$sth->execute;

# fetch the row
my @row = $sth->fetchrow_array;

# dump out the row (array)
print Dumper \@row;

# disconnect from the "csv database"
$dbh->disconnect;


Output using your first file.

c:\test>csv2sql_example.pl

Code
$VAR1 = [ 
'28045281',
'1',
'19',
'DAD',
'12701012015',
'0',
'-261.02',
'01-AUG-14',
'01-AUG-14',
'1'
];


http://search.cpan.org/~timb/DBI-1.631/DBI.pm
http://search.cpan.org/~jzucker/DBD-CSV-0.22/lib/DBD/CSV.pm


(This post was edited by FishMonger on Sep 3, 2014, 8:22 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Sep 3, 2014, 8:22 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives