in reply to Re^2: Append JSON (from hashref)
in thread Append JSON (from hashref)

Yes.

See perldsc on how to manipulate Perl data structures.

You could either add your entry to the result directly, in your Perl code:

$tmp->[0]->{ 'inputPhrase' } = $SearchWord;

... or simply select the search phrase as another column:

SELECT RECNO, DESCRIPTION, ? as inputPhrase FROM RECORDS_TABLE WHERE RECNO LIKE ?
... $sth->execute( $SearchWord, $recno ); ...

Replies are listed 'Best First'.
Re^4: Append JSON (from hashref)
by Anonymous Monk on Apr 06, 2017 at 13:29 UTC
    Thanks, but this first solution means inputPhrase is added in with the details of the first result
    [{"DESCRIPTION":"Description of record","RECNO":"RECORDNumber", "input +Phrase":"RECORDNumber}, ... more records here
    and not outside of the list of results like in the json linked above (won't let me post with the URL here)

      Ah, if you want a different structure, just create that structure.

      Consider writing your data structure in Perl - Perl looks very much like JSON, except that : is spelled => in Perl.

        Can you give some advice on preping this in perl, so far my attempt is failing to produce a structure required:
        while (my $row = $sth->fetchrow_hashref) { print "doc_no: $row->{RECNO} DESCRIPTION: $row->{DESCRIPTION}\n"; $hash{$int} = '"RECNO": "' . $row->{RECNO} . '","DESCRIPTION": "' . +$row->{DESCRIPTION} .'"'; $int ++; } # figure out how to add inputPhrase later.
        Is there a structure I can use which means I don't have to have the $int part?