I've searched the monestary and googled for a possible solution but nothing has come up that i'm not already doing.

I have a HUGE file that i need to parse and insert into a database ( ~334G of text ), and the current code is devouring memory and bringing the system to its knees.

the algorithm i'm currently using:

open( FILE, $filename ) or die " Can't open file ($filename): $!\n"; while ( my $line = <FILE> ) { chomp $line; my @fields = split( /\t/, $line ); ### do some added parsing, then insert }
other nodes, like Quickest way of reading in large files?, reading (caching?) large files, mention the  while loop as the least memory intensive, but shy of trying to split the file into other, smaller files, is there a solution?

UPDATES:
OK, added clarifications.

  1. the RDBMS in question is MySQL 4.1.10
  2. there aren't any wrappers (like Class::DBI or Tie::DBI )
  3. because i need to reorder the fields (well, i need to identify the MLSNumber (since it's real estate data ) and see if the data needs and ins/upd and if the data needs to be inserted into a view ... i don't see the MySQL loader being the right tool for the job ...
and for the rest of the loop:
## outside the loop my @firstLines = qw/ AccessInstr PropType UID Acres MLSNum MediaSource + /; my %firsts = map { $_ => 1 } @firstLines; ## the loop while ( my $line = <FILE> ) { chomp $line; my @fields = split( /\t/, $line ); my $lines = 0; if ( $firsts{$fields[0]} ) { %lookup = map { $lines++ => $_ } @fields; @dbFields = values %lookup; } %reversed = reverse %lookup; $mlsField = $reversed{'MLSNum'}; $mlsNumber = $fields[$mlsField]; $officeListField = $reversed{'OfficeList'}; my $officeList = $fields[$officeListField]; $officeSellField = $reversed{'OfficeSell'}; my $officeSell = $fields[$officeSellField]; next if ( $firsts{$fields[0]} ); while ( scalar( @fields ) != scalar( @dbFields ) ) { push ( @fields, undef ); } $testSth->execute( $mlsNumber ); my $inDB = $testSth->fetchrow(); $jbgTestSth->execute( $mlsNumber ); my $inJBGDB = $jbgTestSth->fetchrow(); my @updateVals ; if ( $inDB ) { my $i = 0; foreach my $loop ( @fields ) { push( @updateVals, $loop ) unless $i == $mlsField; $i++; } push( @updateVals, $mlsNumber ); $updSth->execute( @updateVals ); } else { $insSth->execute( @fields ) unless ( $fields[$mlsField] eq '' ); } if ( ( $officeList && grep( /$officeList/, @offices ) ) or ( $officeSell && grep( /$officeSell/, @offices ) ) ) { if ( $inJBGDB ) { $updSummary->execute( @updateVals ) or warn "no update! : " . $dbh->errstr(); } else { $insSummary->execute( @fields ) } } }

In reply to processing huge files by geektron

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.