Dear Monks, I'm putting together a form to enter data in MySQL but when I look at the data inside the database, I'm getting hash references such as HASH(0x1875380) instead of the expected names.

#!c:\perl\bin\perl use strict; use warnings; use CGI; use DBI; my $q = new CGI; if($q->param("addrecord")){ my %cols = ( servicename => "Name", description => "description", url => "url", help => "helpdesk", group => "grp", hbi => "hbi", riskregister => "register", serviceman => "service_manager", servemail => "man_email", servtel => "man_phone", deputy => "deputy_manager", depemail => "dep_email", deptel => "dep_phone" ); my $keystring = (); my $valuestring = (); my $db = DBI->connect('foo', 'bar', 'baz') or die "Can't connect"; foreach ( qw/ servicename description url help group hbi riskregis +ter serviceman servemail servtel deputy depemail deptel /) { if ({$_}) { $keystring .= $cols{$_} .","; $valuestring .= $db->quote({$_}) .","; } } #remove last comma $keystring =~ s/,$//; $valuestring =~ s/,$//; my $statement = qq( INSERT INTO service_metrics ($keystring) VALUES ($valuestring) ); my $sth = $db->prepare($statement); if (! $sth) { die(sprintf('[FATAL] Could not prepare statement: %s\n\n + ERRSTR: %s\n', $db->errstr())); } $sth->execute(); if (! $sth) { die(sprintf('[FATAL] Could not execute statement: %s\n\n + ERRSTR: %s\n', $db->errstr())); } $sth->finish; $db->disconnect(); } print $q->header(); print $q->start_html(-title=>'New Service'); print "You have added a service";

It is probably the case that I have managed to do something rather silly but I cannot see what it is at the moment and it is driving me nuts. I'm fairly new to Perl and would be grateful if somebody could help me learn what I am doing incorrectly. Thanks.

In reply to Receinving hash where expecting a string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.