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

Hi Perl gurus,

I am using Win32::IEAutomation for automating Gmail. I have couple of question?

A. How do I access the Java script that is running inside, once I sign in?

B. After signing in I am using getAgent() option. This is returing a Hash Reference: Win32::OLE=HASH(0x225b94)

Following is the code I am using to dereference it:

$ie->getAgent(); my %hash = %{$ie->getAgent()}; foreach my $key (keys %hash) { printf "at %s we have %s\n", $key, $hash{$key}; }

But it is printing nothing.

Can any one help me regarding this.

Thanks for any help.

Replies are listed 'Best First'.
Re: accessing data inside HASH(0x225b94)
by Fletch (Bishop) on Feb 12, 2008 at 12:54 UTC

    No experience with this module in particular, but from reading the documentation it looks like you're storing off a reference to an object (a Win32::OLE instance which may or may not be hash based, but that's irrelevant) into another hash. This will loose the object-ness of the underlying object and render it useless. It's also probably not really going to be worthwhile to try and dump any of its internal contents to boot.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: accessing data inside HASH(0x225b94)
by hipowls (Curate) on Feb 12, 2008 at 11:01 UTC

    getAgent returns a hash reference but you are assigning it to a hash. If you had warnings enabled you would have got a message about an odd number of elements.

    my $hash_ref = $ie->getAgent(); foreach my $key ( %{$hash_ref} ) { printf "at %s we have %s\n", $key, $hash_ref->{$key}; }

    Update: changed $hash to $hash_ref

    Update 2: Sorry, please disregard this answer. My response time has been so slow tonight that I got impatient and didn't see the %{} the OP had put in. My apologies and thanks to my unknown benefactor.

      getAgent returns a hash reference but you are assigning it to a hash.

      The OP used my %hash = %{$ie->getAgent()}, which is functionally equivalent to my $hash_ref = $ie->getAgent(); my %hash = %{$hash_ref}. Also, you probably meant using keys in your foreach loop.

        Thank you all for the time and help.

        But any clue for the 1st question?

        How do I access the Java script that is running inside, once I sign in to Gmail?..

Re: accessing data inside HASH(0x225b94)
by nikosv (Deacon) on Feb 12, 2008 at 17:22 UTC
    a collection of hash references?
    use Win32::OLE qw(in); $collection=$ie->getAgent(); foreach $value (in $collection) { print keys %$value; }
    and if you want to access the 'Name' key for example replace the line inside the foreach loop with
    $filename= %$value->{Name};'
      Thanks for the help.

      But after executing this code I am getting the following error:

      Win32::OLE(0.1707): GetOleEnumObject() Not a Win32::OLE::Enum object at C:/Perl/lib/Win32/OLE/Lite.pm line 167.
        Apologies.I have not read the module's documentation and made an incorrect assumption.The docs say that 'getAgent() will return a reference to the Internet Explorer automation object, created using Win32::OLE' so what you expect in return is an object reference which you manipulate as in :
        $ie1=$ie->getAgent(); $ie1->gotoURL('http://www.google.com');