I have made progress from yesterday. I can now read a file in to a database. I am using an IIS log as an example. However, when the log file has fields with values of '0' or ' 0 ', perl reads this as being at the end of the file and stops. By changing all occurences of 0 to an O, will allow the script to complete properly.
if ($UserFile) { print start_html(); # reads the log file and creates a SQL string. The string holds th +e data to create each column # in the table... # This part reads one line of the file and creats a column in a table +for each space-separated item. CreateTable(); $dbh = open_dbi(); my $sth = $dbh->prepare("CREATE TABLE $TableName ($SQLString)") or + err_trap("Cannot prepare the load_category_names query"); $sth->execute or err_trap("Cannot execute the SQL query to CREATE +TABLE"); open IN, "$UserFile"; $z = 0; $B = "\'"; Delimiter(); # I believe this is the problem, but not sure how to fix... while (<IN>) { $TheRec = $_; @NewItem = (); $SQLString = "\'"; $z = 0; chomp $TheRec; @NewItem = split(/$FileDelimiter/, $TheRec); #split the + line in records by space while ($NewItem[$z]) { $SQLString = $SQLString . $NewItem[$z] . "\',\'"; $z=$z + 1; } # removes the trailing comma from the end of the line $LineLength = length($SQLString); $LineLength = $LineLength -2; $SQLString = substr($SQLString,0,$LineLength); my $sth = $dbh->prepare("INSERT INTO $TableName VALUES($SQLSt +ring)") or err_trap("Cannot prepare the load_category_names query"); $sth->execute or err_trap("Cannot execute the SQL query to LOA +D DATA INFILE"); } close_dbi($dbh); } # In this section, I had the same problem, but I added if ($NewItem[$C +olumnNumber] eq 0) {$NewItem[$ColumnNumber] = O}; and the problem was + resolved--all required columns were created... sub CreateTable { $zzz=1; @NewItem = (); open LOGFILE, "$UserFile" or die "Cannot open file $UserFile"; Delimiter(); while (<LOGFILE>) { $TheRec = $_; chomp($TheRec); } $A =(); @NewItem = split(/$FileDelimiter/, $TheRec); #split the + line in records by space # sql code for each column is formed here $ColumnNumber=0; if ($NewItem[$ColumnNumber] eq 0) {$NewItem[$ColumnNumber] = O +}; while ($NewItem[$ColumnNumber]) { $SQLString = $SQLString . "$ColumnName[$ColumnNumber] CHAR +(255),"; $ColumnNumber = $ColumnNumber +1; } # removes the trailing comma from the end of the line $LineLength = length($SQLString); $LineLength = $LineLength -1; $SQLString = substr($SQLString,0,$LineLength); }
Please help--thanks...

In reply to while(INFILE) terminating before finishing file. by sdyates

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.