frank1 has asked for the wisdom of the Perl Monks concerning the following question:
Am trying to get my output of data to this format
({ "items": [ { "title": "Valls" }, { "title": "AUT15605" }, { "title": "10UT15605" } ] })
Am getting this error with my code
Can't modify private hash in concatenation (.) or stringmy $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { RaiseError => 1, }) or die $DBI::errstr; my $sth = $dbh->prepare("SELECT titles FROM tbl_1"); $sth->execute(); my $Data = $sth->fetchall_arrayref(); my %output; foreach my $Data (@$Data) { my ($title) = @$Data; %output .= ( 'items' => [("title" => "$title")] ); } my $results = to_json(\%output); print "Content-type: text/html\n\n"; print $results;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Returning data
by jeffenstein (Hermit) on Apr 20, 2024 at 20:48 UTC | |
by cavac (Prior) on Apr 20, 2024 at 22:34 UTC | |
by frank1 (Monk) on Apr 21, 2024 at 08:55 UTC | |
by frank1 (Monk) on Apr 21, 2024 at 08:53 UTC | |
Re: Returning data
by Marshall (Canon) on Apr 21, 2024 at 10:25 UTC | |
by frank1 (Monk) on Apr 21, 2024 at 12:33 UTC | |
Re: Returning data
by johngg (Canon) on Apr 20, 2024 at 20:53 UTC | |
by frank1 (Monk) on Apr 21, 2024 at 08:45 UTC | |
Re: Returning data
by BillKSmith (Monsignor) on Apr 21, 2024 at 21:23 UTC | |
Re: Returning data
by TheloniusMonk (Sexton) on Apr 22, 2024 at 12:13 UTC | |
by marto (Cardinal) on Apr 22, 2024 at 12:16 UTC |