Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Parsing data from JSON response file.

by tangent (Parson)
on Apr 11, 2020 at 04:02 UTC ( [id://11115362]=note: print w/replies, xml ) Need Help??


in reply to Parsing data from JSON response file.

If the data is as you show in the example then you do not need the loop, you can just access whatever you need directly. To see what is happening within your loop, add another print statement:
for my $key ( keys %$data ) { print "key: $key\n"; ...

Replies are listed 'Best First'.
Re^2: Parsing data from JSON response file.
by Marshall (Canon) on Apr 13, 2020 at 03:12 UTC
    Good idea. That is actually one of the first things I did when running the code. And then came the realization that $key wasn't used anywhere within the loop!
    for my $key ( keys %$data ) { print "key = $key\n"; #debug my $zip = $data->{'zip'}; my $descri = $data->{'happen'}[0]->{'descri'}; my $extra_name = $data->{'notas'}[0]->{'ExtraName'}; print "\n $zip - $descri - $extra_name\n"; }
    I guess this is "off topic", but a feature of Perl.

    If you have a constant like: use constant DEBUG => 1; and then have a statement like print "whatever line(s)" if DEBUG;, Perl is smart enough to eliminate this statement from the executable code when DEBUG is false (set to zero). For complex modules, I often leave code like that in the source. When I add a new feature, I turn debugging on. Print is your friend. I seldom need the Perl debugger.

      Marshall:

      That's easy enough to verify with B::Concise:

      $ cat foo.pl use strict; use warnings; use constant DEBUG=>0; print "Foo bar!\n"; print "Baz\n" if DEBUG; $ perl -MO=Concise,-exec foo.pl 1 <0> enter 2 <;> nextstate(main 191 foo.pl:5) v:*,&,{,x*,x&,x$,$ 3 <0> pushmark s 4 <$> const[PV "Foo bar!\n"] s 5 <@> print vK 6 <;> nextstate(main 191 foo.pl:6) v:*,&,{,x*,x&,x$,$ 7 <@> leave[1 ref] vKP/REFC foo.pl syntax OK

      Yep, it's stripped out!

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115362]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found