In addition to Corion's comments the first line of this sub is incorrect, the scalar $ref will be 1, the count of elements in @_

sub hash_display_listing{ # my $ref = @_; my ($ref) = @_; # or # my $ref = shift ;
$sth->execute($searchterm) or die "Unable to execute query: " . $sth->errstr; warn("Finished sub search record"); $result = generateResponseHash($sth);

You are calling $sth->execute() twice, first time with a parameter and again in generateResponseHash($sth) without parameter

Breaking long code into subroutines is usually good practice but be careful not to overdo it :)

elsif ($action eq "updatetable_167"){ warn("Entered updatetable_167"); my $kind = $query->param('kind'); die "ERROR \$kind='$kind'" if ($kind < 0 || $kind > 2 ); my $searchterm = $query->param('searchterm'); warn("\$searchterm = '$searchterm'"); my $searchfield = ['userid','lastname','business']->[$kind]; warn("\$searchfield = '$searchfield'"); my $stmt = "SELECT * FROM users WHERE $searchfield = ?"; warn("\$stmt = '$stmt'"); my $sth = $dbh->prepare($stmt); $sth->execute($searchterm); warn("Finished sub search record"); my $count = $sth->rows; warn("\$count = '$count'"); if ($count == 0) { warn("Failed Search: '$searchfield' equal to '$searchterm' "); } else { my $ref = $sth->fetchrow_hashref(); my $hashref = hash_display_listing($ref); completeResultHash( $hashref ); } $sth->finish (); } sub hash_display_listing{ my ($ref) = @_; my %hash = %$ref; print Dumper \%hash; return \%hash; } sub completeResultHash{ my $hashref = shift; warn("completeResultHash line 631"); my $json_str = encode_json($hashref); print $json_str; warn("after jason_str print"); }
poj

In reply to Re^11: CGI Action call by poj
in thread CGI Action call by tultalk

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.