I just installed the javascript.pm module under win32 and it seems to be
working great with activestate's perl port, but I am having a problem with
one aspect of using it.
I read a single sentence in the docs that says that you need to create a
new context prior to running a new script query, so I'm doing this, but it
still returns the same answer?!? It is complicated a bit because I'm
actually grabbing a web page, then parsing out a specific javascript
function from it, then storing that function in a Perl variable, then
using the JavaScript.pm routines to "run" that javascript code. This seems
to work fine, and I get the correct answer the first time, but then after
grabbing the next web page (in a loop) even though there is a different
javascript function in the variable to be executed, the answer never
changes?? What am I doing wrong? Here's some code (not the complete
program):
while(!$eof) {
$ua = LWP::UserAgent->new();
$response = $ua->get($new_URL,Referer=>$new_URL);
die "OOPS!!! - $response->status_line\n" if $response->is_error();
$content = $response->content();
$content =~ tr/\x0a//; $content =~ tr/\x0d/\n/;
(my $func_next) = $content =~ /Next.+\x7b(.+)this.+\x7d/is;
$func_next = 'function Next(item){' . $func_next . 'xx=h; write(xx);}';
# now interpret the javascript code and return the answer
$cx = $rt->create_context();
$cx->bind_function(name=>'write',func=>sub{ ($answer) = @_ });
$cx->eval( $func_next );
$cx->call("Next","1");
print "answer=$answer\n";
$eof = 1 if $answer < 0;
}
When this is run it works fine through the first loop, but then every loop
thereafter it always prints the same value for $answer but the $func_next
variable contains the new page's updated code. How can that be happening?
It seems like the code is being compiled once then not interpreted again,
even though i'm eval'ing it again and again...what am I missing here?
Thanks!
Tim