Here is my dilemma. I basically have a snippet that comes with the Spreadsheet::ParseExcel module - and another script
that loads the output into a database. My problem is that I don't want to print the info from the parse to a file and then have the second script read that file - I just want it to be seen internally - does that make sense?? thanks monks
#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $oExcel = new Spreadsheet::ParseExcel; #1.1 Normal Excel97 my $oBook = $oExcel->Parse('Excel/BBI.xls'); my($iR, $iC, $oWkS, $oWkC); print "FILE :", $oBook->{File} , "\n"; print "COUNT :", $oBook->{SheetCount} , "\n"; print "AUTHOR:", $oBook->{Author} , "\n"; for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) +{ $oWkS = $oBook->{Worksheet}[$iSheet]; print "--------- SHEET:", $oWkS->{Name}, "\n"; for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $i +R++) { for(my $iC = $oWkS->{MinCol} ; defined $oWkS->{MaxCol} && $iC <= $oWkS->{ +MaxCol} ; $iC++) { $oWkC = $oWkS->{Cells}[$iR][$iC]; print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC) +; } } } # This helps make sure we're using the vars we mean to use use strict; # use DBI; # you'll need to add the dbi / oracle info +? my $oldrow = 0; my @field_names = qw(fieldname_one fieldname_two fieldname_three); my (@fields,@values); # my $dbh = DBI->connect(...,...,...); # my $sth; open DATA, "< myfilename" or die "myfilename: $!\n"; while(<DATA>) { print; chomp; # this puts the row number in $1, col number in $2 and data in $3, # and in the variable respectively my ($row,$col,$data) = /^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*=>(.*)$/; # if we've finished with last entry, enter it into database if (($oldrow != $row) && ($oldrow)) { print "Adding $oldrow\n"; if(@fields) { #make sure there is data my $query = 'INSERT INTO tablename (' . (join ',', @fields) . ' VALUES(' . (join ',', @values) . ')'; # ... do DB calls ... # $sth = $dbh->prepare($query) || die "prepare: $query"; # $sth = $dbh->execute || die "execute: $query"; # $sth->finish; @fields = @values = (); } $oldrow = $row; } push @fields, $field_names[$col]; # field name with proper data #push @values, db->quote($data); #run data through DB quoter push @values, $data; } # $dbh->close; close DATA;

In reply to Writing Spreadsheet parse to Database by JSchmitz

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.