joec_ has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I think im missing something...

use SOAP::Lite; ##...soap setup done here....## my $result = $soap->search(SOAP::Data->name('searchString',$search)); foreach my $r (%$result){ print $r->result->{Person}->{commonname}; }
This code searches for people (ldap i think). It works fine if the searchString is something unique to a person i.e a login id but if i use a common surname i.e. shaw, i get this error:
Pseudo-hashes are deprecated at ./searchPeople.pl line 23. Argument "\x{53}\x{68}..." isn't numeric in hash element at ./searchPe +ople.pl line 23. Bad index while coercing array into hash at ./searchPeople.pl line 23.

Its obviously a syntactic thing, to do with hashes of hashes or some such, but i just cant work it out.

The argument isnt numeric bit -> \x{53}\x{68} converts to Sh from Shaw i guess.

Thanks

Joe

Eschew obfuscation, espouse eludication!

Replies are listed 'Best First'.
Re: SOAP::Lite and hash of hashes
by jethro (Monsignor) on Feb 12, 2009 at 14:39 UTC

    In the foreach you are converting the hash into an array and loop through all the keys and values. So $r is a key in the first iteration, then a value, then a key. $r->result makes no sense either, since 'result' is the name of the hash and should be before the key

    foreach my $r (keys %$result){ print $result->{$r}->{Person}->{commonname}; }

    $result is a pointer to a hash and $r is now a key of it (note the keys function)

      Thanks for the reply - that code gives me:Cant coerce array into hash. What does that mean? Also - as far as i know with soap, $result->result is a method called on the $result variable

      Thanks

      -----

      Eschew obfuscation, espouse eludication!

        Ah sorry, that that was an object method didn't cross my mind. I probably can't really help you as I don't know Soap::Lite and I didn't find the search method in its documentation. But one thing is certain, your foreach is not right. It might be one of these:

        foreach my $r (keys %$result){ print $r->result->{Person}->{commonname}; } foreach my $r ($result->result){ print $r->{Person}->{commonname}; } foreach my $r (@$result){ print $r->result->{Person}->{commonname}; }

        If not, you might use Data::Dumper to check out the data structure of $result. Or look for an example in the documentation of the search method

        The error message 'Can't coerce...' means there is an array somewhere and we access it as a hash. Data::Dumper is your friend here.

        UPDATED