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

In reply to Simplified NYSE stock price extraction script by Scott7477

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.