[Jax.PM] ~9M lines of data
iudicium ferat
sneex at bellsouth.net
Mon Oct 14 11:25:03 CDT 2002
I am somewhat beating my head against a brick wall here - so I think "Hey!
This sounds like a Fun With Perl project :)"
Here is the challenge -
You are presented with a MySQL Schema dump that is less than 9 million rows;
you should read the data row by row, finding each CREATE TABLE statement,
and displaying the next ~50 lines INCLUDING this line - do this recursively
until end of file is reached.
My brute force efforts, while slow, are generally working - I am wondering -
could this become MORE FUN ?
My brute force method -
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
$|++;
my $ctr;
my $flag;
open (RFILE, "<Daily_bb551_20021410000103286.dump") or
die "\n\nCan't open Schema.Raw for reading: $!\n\n";
open (NFILE, ">Schema.Cooked") or
die "\n\nCan't open Schema.Cooked for writing: $!\n\n";
while (<RFILE>) {
$ctr++; # Count lines read...
s/\n/ /; # newline to space...
s/^\s+//; # compress leading whitespace...
s/\s+$//; # compress trailing whitespace...
next unless length; # anything to process?
# CREATE TABLE
if (/^CREATE\sTABLE\s\(/) {
print NFILE "\n\n$_\n";
$flag++;
next;
}
# End of segment
if (/^\#\sDumpings\datas\for\stable\s\'/) {
--$flag;
next;
}
# Get data, while $flag
if ($flag) {
print NFILE " $_\n ";
next;
}
# Everything else is skipped
# during natural looping...
} # end while loop
close (RFILE) or die "\n\nCan't close Schema.Raw: $!\n\n";
close (NFILE) or die "\n\nCan't close Schema.Cooked: $!\n\n";
print "\nProcessed $ctr lines...\n\n";
__END__
Example of the snapshot -
# Table structure for table 'addressbook'
#
CREATE TABLE addressbook (
.
. Get everything here ...
.
PRIMARY KEY (pk1,sos_id_pk2),
KEY addrbk_users_fk_i (users_pk1,users_sos_id_pk2)
);
#
# Dumping data for table 'addressbook'
The line above denotes end of this segment;
skip all data until next segment area...
Any helpful mumblings would be appreciated :)
Thx!
-Bill- :]
_Sx____________________
('> iudicium ferat
//\ Have Computer -
v_/_ Will Hack...
More information about the Jacksonville-pm
mailing list