Henrik Nilsson wrote:
>> What Perl binary hash file? I was referring to the contents of the
>> database (tables, procedures, constraints, etc). If you have a binary
>> object stored in the dB, export/import won't make it portable.
>
> No, this was no Oracle database matter but a Perl hash file (which I
> think is in binary format) matter. Sorry, perhaps I didn't make this
> clear. So the problem is really, how to make such a file work on
> another os...?

1) If you can get the data you need out of Oracle, use its
   exp/imp programs, otherwise:

2) If you're trying to move a small DBM file (one of the AnyDBM_File
   derivatives) from one platform to another, follow these steps. By
   "small", I mean that it will fit in your system's virtual memory.

  A) Open the database with tie() like usual.

     # replace "SOME_File" with the right module name.
     tie my %database, 'SOME_File', 'filename', ...

  B) use Storable's nstore to store a portable binary representation:

     # note, you cannot store by reference, you must make a copy.
     use Storable qw(nstore);
     nstore({%database}, 'filename.bin') || die $!;

  C) On the destination system, use Storable's retrieve to load the
     data, and put it back into the database.
     
     use Storable qw(retrieve);
     $db_data = retrieve('filename.bin') || die $!;
     %database = %$db_data;

3) If you're trying to move a *large* DBM file (larger than will fit in
   virtual memory), you'll need to dump it a little at a time. Using a
   CSV file is an option:

  A) Open the database with tie() like usual.

     # replace "SOME_File" with the right module name
     tie my %database, 'SOME_File', 'filename', ...

  B) Iterate over the name/value pairs (using "each" -- not "keys"), and
     store each one in the CSV file.

     use Text::CSV_XS;
     my $csv = Text::CSV_XS->new(); # be sure to read perldoc
     while (my ($k,$v) = each %database) {
        $csv->combine($k,$v)
            || die "can't combine row for key '$k'";
        print OUTFILE $csv->string(), "\n";
     }

  C) On the destination system, read the CSV file and populate the
     database file with its contents.

     use Text::CSV_XS;
     my $csv = Text::CSV_XS->new();
     while (<>) {
         $csv->parse($_) || die "can't parse line $.";
         my ($k,$v) = $csv->fields;
         $database{$k} = $v;
     }


Regards,
Philip

Reply via email to