I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2011-01-08 15:37:47.320402-08 by ninuzzo
iterate through a collection
I've read with interest about the necessity of type casting here:
http://search.cpan.org/~patl/Inline-Java-0.52/Java.pod#TYPE_CASTING
I am trying to apply the same recipe to traverse a collection returned by WWW::HtmlUnit but casting did not help. The problem lies in accessing a private inner class through an Inline::Java link. In fact the error I get is:
You are not allowed to invoke method toArray in class java.util.Collections$UnmodifiableRandomAcces +sList: Class InlineJavaUserClassLink can not access a member of class java.util.Collections$Unmodi +fiableCollection with modifiers "public"
Found below a bit of code to reproduce my problem. Is there any fix for that or an alternative way to implement something like the Java enhanced for loop with Inline::Java?
use WWW::HtmlUnit; use Inline::Java 'cast'; my $browser = WWW::HtmlUnit->new(); my $page = $browser->getPage( 'http://google.com/search?q=God' ); my $table = $page->getHtmlElementById('nav'); my $rows; # Here I get the above error... $rows = $table->getRows( )->toArray; # This does not work either. I think because UnmodifiableRandomAccessList # is defined as a private (not public) inner class of java.util.Collections. $rows = cast('java.util.Collections$UnmodifiableList', $table->getRows( ))->toArray;
Direct Responses: 13135 | 13136 | Write a response
Posted on 2011-01-08 17:10:36.989148-08 by patl in response to 13134
Re: iterate through a collection
This code works well for me:
use strict ; use WWW::HtmlUnit; use Inline::Java 'cast'; my $browser = WWW::HtmlUnit->new(); my $page = $browser->getPage( 'http://google.com/search?q=God' ); my $table = $page->getHtmlElementById('nav'); my $rows = $table->getRows()->toArray(); my $i = 0 ; foreach my $row (@{$rows}){ print "row $i: " ; my $cells = $row->getCells()->toArray() ; my $j = 0 ; foreach my $cell (@{$cells}){ print "cell $j " ; $j++ ; } print "\n" ; $i++ ; }
Prints:

row 0: cell 0 cell 1 cell 2 cell 3 cell 4 cell 5 cell 6 cell 7 cell 8 cell 9 cell 10 cell 11
Direct Responses: Write a response
Posted on 2011-01-08 19:27:36.541089-08 by awwaiid in response to 13134
Re: iterate through a collection
Using Inline::Java 0.52_90, this works much better. In fact, 0.52_90 seems plenty release-worthy as 0.53 to me! --Brock
Direct Responses: Write a response