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

No

Replies are listed 'Best First'.
Re^5: CGI Action call
by poj (Abbot) on Mar 12, 2018 at 20:10 UTC

    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

      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