Patrick, this did the trick. AUTOSTUDY => 1 exposed everything I needed to get 
the data from that object. Perfect.

My confusion came from returning arrays from other methods and being able to 
dereference them. 

$r = $mstrAdmin->getGroupForUser(myuserid)

print $r
Inline::Java::Array=ARRAY(0xc00a38) 

@w = @$r
print join "\n", @w

Group 1
Group 2
Group 3
Group 4
Group 5
Group 6

I wasn't paying attention to the "::Object=" in 
Inline::Java::Object=HASH(0xaae924)

Thanks for setting me straight.
Mike

-----Original Message-----
From: Patrick LeBoutillier [mailto:patrick.leboutill...@gmail.com] 
Sent: Wednesday, January 26, 2011 6:04 PM
To: VANOLE, MICHAEL J (ATTSI)
Subject: Re: Inline Java - dereferencing

Michael,

On Wed, Jan 26, 2011 at 4:58 PM, VANOLE, MICHAEL J (ATTSI)
<mv5...@att.com> wrote:
> Hi, this may be a basic perl question. I'm using inline::java to execute
> some public methods like this one:
>
>        public User findUserByLogin(String loginName, boolean populate)
> {
>                User ret = null;
>                try {
>                        ret = impl.findUserByLogin(loginName, populate);
>                } catch (ExecuteException e) {
>                        this.trapError(1, "Error looking up user.
> loginName=" + loginName
>                                            + " populate =" + populate +
> "\nERROR:"
>                                            + e.getMessage(), e);
>                }
>                return ret;
>        }
>
> I call it:
> $obj = $mstdAdmin->findUserByLogin('myuserid',1);
>
> Print "$obj\n";
> Inline::Java::Object=HASH(0xaae924)

That fact that you get a reference to an Inline::Java::Object object
means that Perl doesn't know about that object's class (User). Try
adding AUTOSTUDY => 1 to your Inline::Java options:

use Inline (
  Java => ...,
  AUTOSTUDY => 1,
) ;

That will make Perl automatically learn about all the Java classes it
encounters.

Also, you don't dereference the ref, you call methods on it, in this
case public methods of the User class. i.e.:

my $name = $obj->getName() ;

(Here I assume that there is a "public String getName()" method in the
User class, which is probably not the case...).

If you need more help try posting a complete example, that way I can
run it and point you in the right direction.

Patrick

>
> I'm having a helluva time trying to dereference this
>
> %hash = %$obj;
> foreach my $k (keys %hash) {print "$k: $hash{$k}\n";}
>
> prints nothing.
>
> (undef,$h) = split(/\=/,$obj);
> %hash = %$h;
> foreach my $k (keys %hash) {print "$k: $hash{$k}\n";}
>
> prints nothing.
>
> Is there a trick?
>
> Many thanks,
> mike
>
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada

Reply via email to