I am building a simple Mason application to manage the addresses for a friend's organization. The platform is RH 9, Apache 2, Mason, Perl 5.8, and PostGres.

I've run across the error from the title in an odd and frustrating manner. In writing the edit-record function, I created a large form, each element of which I named, for consistency, the same name as the corresponding db field. The user makes whatever edits they wish, and the form get submitted to a second file (submit.html) which in turn hands \%ARGS to the subroutine Green::modifyRec, like so:

submit.html:

[...] if ((my $foo = Green::updateRec(\%ARGS))) { [...]
Green.pm:
sub updateRec { $new = shift @_; [...]
So far, so good, or so I thought. Initially, the troubling line was this one, which returned the error above, specifically as "Can't use string ("precinct") as HASH ref in line 96":
$sth->execute($new->{first}, $new->{middle}, $new->{last}, $new +->{address}, $new->{city}, $new->{state}, $new->{zip}, $new->{email}, + $new->{county}, $new->{precinct}, $new->{region}, $new->{home}, $new +->{other1}, $new->{other2}, $new->{work}, $new->{ext}, $new->{occupat +ion}, $new->{id});
I figured I had a problem with the word itself -- though it's kind of nonintuitive to have it fuss about a string in the MIDDLE of a line -- so I first renamed it, and then removed it entirely.

No joy; it was clearly being vexed by "precinct" 's existence in the HASH on a basic level, not because of something being done here. Additionally, removing this line and simply trying to address the hash in a simple debugging line like this:

print STDERR "\n SHAZAM!!!! $new->{middle} \n";
Still produces the error. Removing "precinct" from the original form, of course, keeps it from complaining about that particular string, but it moves on to another one.

It seems clear that I'm doing something wrong on a basic level; the code is not complex, but I can't for the life of me figure it out. It does seem likely that either (1) someone will slap me with the answer quickly or (2) I'll realize the answer as soon as I press "submit" on this post. I really don't care which.

Thanks in advance.

Chet Farmer


In reply to Ah, the old "Can't use string ("string") as a HASH ref" 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.