Re: Struggling with Perl data structure for JSON object
[email protected] (Niels Jakob Darger) Sat, 10 Dec 2011 23:26:37 +0100
| Newsgroups | perl.copenhagen |
|---|---|
| Message-ID | <[email protected]> |
No worries :-) Jakob On 2011-12-10 18:46, Thomas Elsgaard wrote: > 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