CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [robertico] Parse JSON with PERL: Edit Log



Zhris
Enthusiast

Mar 22, 2013, 2:21 AM


Views: 800
Re: [robertico] Parse JSON with PERL

Hi Robertico,

What you are seeing in "output" is Data::Dumper stringifying the data structure for easier reading.

In your case you are dealing with a simple one level hash reference ($perl_ref).

You can loop through it:

Code
while ( my ( $key, $value ) = each ( %$perl_ref ) ) 
{
print "$key, $value\n";
}


Or access each value directly by its key:

Code
print $perl_ref->{from_id} . "\n"; 
print $perl_ref->{message_id} . "\n";
print $perl_ref->{to_id} . "\n";
print $perl_ref->{message} . "\n";


etc...

For more complex data structures, particular those that may vary in levels with unknown keys, you could use a recursive processing routine.

Chris


(This post was edited by Zhris on Mar 22, 2013, 2:23 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Mar 22, 2013, 2:23 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives