Quoth David Karr <
davidmic...@gmail.com>:
>
> sub countJSONServices($) {
> my ($jsonText) = @_;
> my $json = JSON->new->allow_nonref;
This line does nothing useful. Why is it there?
> my $scalar = from_json($jsonText);
> printhash($scalar);
> my $serviceCallResults = $scalar->{"sl.serviceCallResults"};
> #print "serviceCallResults[" . $serviceCallResults . "]\n";
> printhash($serviceCallResults);
> my $services = $serviceCallResults->{"sl.services"};
> printhash($services);
> my $servicesList = $services->{"sl.service"};
> print "servicesList[$servicesList]\n";
> for my $service (@servicesList) {
You're not using 'strict'. Bad programmer, no cookie!
$servicesList and @servicesList are completely different variables. You
want to deref the arrayref in $servicesList, that is, @$servicesList.
(You might want to consider using less verbose variable names. That much
repetition makes the code extremely hard to read.)
> print "service[$service]\n";
> }
> my $servicesCount = scalar @servicesList;
> print "servicesCount[$servicesCount]\n";
> return $servicesCount;
> }
>
> Where "printhash()" simply is this:
>
> sub printhash($) {
> my ($hash) = @_;
> while ( my ($key, $value) = each(%{$hash}) ) {
> print "$key => $value\n";
> }
> }
You might want to consider using Data::Dumper or Data::Dump instead.
Ben