The error indicates that the content you are interpolating contains
unescaped single quotes, which confuses the parser, since you are using
single quotes as the string delimiters. It's like doing:
    print "This text is "quoted" when printed\n";

Call $dbhandle->quote() on each string to correct this.

As far as using storable, I agree with what has been said before, adding
that I would only use it if it was critical that you maintained the state of
the hash or whatever, and its contents aren't actually table data. Even in
that case creating a temporary/permanent table to hold the data is more
extensible.

-K

"Do not meddle in the affairs of wizards, for they are subtle and quick to
anger."


> From: Sean Carte <[EMAIL PROTECTED]>
> Date: Fri, 16 Mar 2001 14:55:45 +0200
> To: [EMAIL PROTECTED]
> Subject: [MacPerl] Storable.pm -- freezing data structures
> 
> 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