in reply to Re^4: CGI Action call
in thread CGI Action call

In which case instead of this

while (my $ref = $sth->fetchrow_hashref ()){ # #warn("generateResponseHash line 587 ref: '$ref'"); hash_display_listing ($ref); ++$count; } $sth->finish (); completeResultHash(%hash_record);

you could just do

my $result = $sth->fetchrow_hashref(); my $json_str = encode_json($result); print $json_str; exit(0);
poj

Replies are listed 'Best First'.
Re^6: CGI Action call
by tultalk (Monk) on Mar 13, 2018 at 02:20 UTC

    Hi

    Tried what you suggested and got the following error:

    hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at

     my $json_str = encode_json($result);

    I tried the allow-nonref (\) and still does not work.

      hash- or arrayref expected

      That's because $result is undefined, ie no records were found so you need to decide how to handle that. You could simply encode an empty hash.

      my $json_str = encode_json( $result || {} );
      poj

      Tried what you suggested and got the following error: I tried the allow-nonref (\) and still does not work.

      Hi,

      What do you think is happening?

      What is $result?

      See Basic debugging checklist

        Quite possibly if I knew these answers

        What do you think is happening?What is $result?

        I would not be here seeking your wisdom

        I would like to see what is in result using datadumber but don't know how to get it to work