Re: Struggling with Perl data structure for JSON object
[email protected] (Thomas Elsgaard) Sat, 10 Dec 2011 18:46:55 +0100
| Newsgroups | perl.copenhagen |
|---|---|
| Message-ID | <CAKSYKuKwSGP8YbVZ5ten9E52yLU2aWab-fF4FvbF8-f2-Dp-ig@mail.gmail.com> |
On Sat, Dec 10, 2011 at 6:38 PM, Niels Jakob Darger <[email protected]> wrote: > Ah, I see. How about something along the lines of: > > my @servers; > while (my $ref = $sth->fetchrow_hashref()) { > push @servers, $ref; > } > print encode_json(\@servers); > > Or, if you need the full structure (your example suggests not): > > my $data = [ > { > servers => [] > } > ]; > > while (my $ref = $sth->fetchrow_hashref()) { > push @{$data->[0]{servers}}, $ref; > } > Hi Niels Damnn i need to read some more about Perl data structures, that was much more simple than i thought, it works like a charm Thanks a lot for the help!! ///Thomas