This script is an improved version of the code I posted here:
use strict; use Text::CSV::Simple; use DBI; use DBD::SQLite; #usage singlenyse.pl NYSE091806.csv 091806 my $filename = shift; my $day= shift; my $tmpfile = "nyse.tmp"; open my $out, '>', $tmpfile or die "Couldn't open $tmpfile for writing: $!"; my $parser = Text::CSV::Simple->new(); $parser->want_fields(1, 2, 3, 4, 5, 8); my @data = $parser->read_file($filename); my $datalines = @data; for my $row(@data) { my @line = @$row; foreach my $row1(@line) { print {$out} $row1."\t"; } print {$out} "\n"; } close $out or die "Couldn't close $tmpfile: $!"; #This section eliminates certain unwanted lines open(DATA, $tmpfile) || die("can't open $tmpfile: $!"); while (my $lines = <DATA> ) { chomp($lines); if (substr($lines,0,1) ne "\s") { if (substr($lines,0,4) ne "Symb") { if ( not $lines =~ m/\S/msx ) { next; } print {$out} $lines."\n"; } } } close DATA; #This inserts the extracted data into a SQLite database my $datapath = "c:/sqlite3/nyse.db"; open(DATA, $tmpfile) || die("can't open $tmpfile: $!"); my $dbh = DBI->connect("dbi:SQLite:c:/sqlite3/nyse.db","",""); my $sth = $dbh->prepare("INSERT INTO DATA(Symbol, Open,High, Low, Clos +e, Volume, Date) VALUES (?, ?, ?, ?, ?, ?, ?)"); while(<DATA>) { chomp; my ($sym,$opn,$hi,$lo,$cls,$vol) = split /\t/; my $rc=$sth->execute($sym,$opn,$hi,$lo,$cls,$vol,$day); } $sth->finish; $dbh->disconnect; close DATA; unlink $tmpfile; #cleans up the temp file