[Jax.PM] ~9M lines of data

Aaron Johnson solution at gina.net
Mon Oct 14 13:45:29 CDT 2002


I am very curious as to the reason you would want to do this.  You don't
seem to be excluding any specific information in the rewrite, if you
just want the create statements you can do a mysqldump -d

I suppose if you just have the dump and are doing to be creating them
then this might be a useful process.

Aaron Johnson

On Mon, 2002-10-14 at 12:25, iudicium ferat wrote:
> [a jax.PM member posting]
> 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...
> 
> 
> _______________________________________________
> Jacksonville-pm mailing list
> Jacksonville-pm at mail.pm.org
> http://mail.pm.org/mailman/listinfo/jacksonville-pm
> 




More information about the Jacksonville-pm mailing list