I'm trying to store hashes in a PostgreSQL database, and thought that 
Storable's freeze would provide a solution:

#!/usr/bin/perl -w

use strict;
use Storable qw(nfreeze thaw);

my ($name, @dwarves, @jobs, %occupations, $dwarf, $i, );

my ($dbhandle );

$name = 'set_1';
@dwarves = qw(Happy Grumpy Dopey Doc);
@jobs = qw(Entertainer Worker Lecturer Manager);
$i = 0;
foreach $dwarf (@dwarves) {
     $occupations{$dwarf} = $jobs[$i];
     $i++;
}

my $dwarves_str = nfreeze \@dwarves;
my $occupations_str = nfreeze \%occupations;

print "$dwarves_str\n";
print "$occupations_str\n";

# @dwarves = @{ thaw($dwarves_str) };
# %occupations = %{ thaw($occupations_str) };

exit 1;
__END__

On the server the following line would add the data to the PostgreSQL database:

$dbhandle->do( "INSERT INTO $table
                (name, dwarf_list, occupations)
               VALUES(\'$name\', \'$dwarves_str\', \'$occupations_str\')" );

However, I get the following error:

DBD::Pg::db do failed: ERROR:  Unterminated quoted string
Database handle destroyed without explicit disconnect.

which seems to be to do with the serialized data, which seems to 
contain return characters. Is there a way around this? Am I on the 
right track in using Storable to begin with?
-- 
My brain hurts!
SeanC
                      Mediatek Training Institute
            26 Crart Ave., Berea, Durban, South Africa 
<-- New Address
    phone: +27 (0)31 202 1886              [EMAIL PROTECTED] <-- 
New Phone Number
       fax: +27 (0)31 202 1767 
<-- New Fax Number
                   <http://members.nbci.com/s_carte/>

Reply via email to