I was just writing a bug off in DBD::ODBC when I needed to check the ParamTypes documentation and discovered it had a mistake:

# assuming $sth1 is a previously prepared statement handle my $sth2 = $dbh->prepare( $sth1->{Statement} ); my $ParamValues = $sth1->{ParamValues} || {}; my $ParamTypes = $sth1->{ParamTypes} || {}; $sth2->bind_param($_, $PV->{$_} $PT->{$_}) for keys %{ %$PV, %$PT }; $sth2->execute();

which should I guessed was just a typo and should be

# assuming $sth1 is a previously prepared statement handle my $sth2 = $dbh->prepare( $sth1->{Statement} ); my $ParamValues = $sth1->{ParamValues} || {}; my $ParamTypes = $sth1->{ParamTypes} || {}; $sth2->bind_param($_, $ParamValues->{$_} $ParamTypes->{$_}) for keys %{ %$ParamValues, %$ParamTypes }; $sth2->execute();

Before I committed the fix to DBI pod I thought I'd better check it out so I wrote:

use strict; use Data::Dumper; use DBI; my $h = DBI->connect; my $s = $h->prepare(q/insert into mje values(?)/); $s->bind_param(1, 2); $s->execute; my $ParamValues = $s->{ParamValues} || {}; my $ParamTypes = $s->{ParamTypes} || {}; print Dumper($ParamValues); print Dumper($ParamTypes); my $s2 = $h->prepare(q/insert into mje2 values(?)/); $s2->bind_param($_, $ParamValues->{$_}, $ParamTypes->{$_}) for keys %{ %$ParamValues, %$ParamTypes };

and it fails with "Can't use string ("1/8") as a HASH ref while "strict refs" in use at /tmp/z.pl line 18.". I've no idea why - any ideas?

The output which will make it easier to reproduce without DBI is:

$VAR1 = { '1' => 2 }; $VAR1 = { '1' => { 'TYPE' => 4 } }; Can't use string ("1/8") as a HASH ref while "strict refs" in use at / +tmp/z.pl line 18.
UPDATE: posted wrong code at first - sorry.

In reply to Problem with hash dereferencing from DBI example by mje

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.