Click to See Complete Forum and Search --> : Errors in debugging cgi script /Viewing


spanish
01-20-2009, 03:54 AM
Hello

Please i need some assistance with running a cgi script in perl editor.
I have obtained a Google API key, installed a perl editor on my computer to enable me run the program.

The errors obtained are :

Useless use of a constant in void context at Untitled line 12 "SOAP::Lite" ;
Use of uninitialized value in concatenation(.) or string at (eval 8) line 15 " use List ::Until qw(max min)" ;
Use of uninitialized value in concatenatiom(.) or string at Untitled line 62 " $x = '+" ' . $query->param('term1') . ' " " ;
Use of uninitialized value in concatenatiom(.) or string at Untitled line 63 " $x = '+" ' . $query->param('term2') . ' " " ;
Can`t locate object method "service" via package "SOAP::Lite" (perhaps ypu forgot to load "SOAP::Lite"?) at Untitled line 30.

This are the errors displayed on the perl browser.

And the source code is :

#!"C:\Program Files\xampp\perl\bin\perl.exe"
# ngd-calculator.cgi
#
# wjt
# http://history.uwo.ca/faculty/turkel/
#
# 5 aug 2006

use SOAP::Lite;
use CGI;
use POSIX qw(log10);
use List::Util qw(max min);

# Google API developer's key
my $google_key = '<Insert Key Here>';

# Google WSDL
my $google_wsdl = "http://api.google.com/GoogleSearch.wsdl";
# my $google_wsdl = "./GoogleSearch.wsdl";

# start, maxResults, filter, restrict, safeSearch, lr, ie, oe
my @params = (0, 10, 0, '', 0, '', 'utf-8', 'utf-8');

# Do Google search and return count
sub do_search {
unshift (@params, ($google_key, $_[0]));
my $result =
SOAP::Lite
-> service($google_wsdl)
-> doGoogleSearch(@params);
shift @params;
shift @params;
return $result->{estimatedTotalResultsCount};
}

# Create the search page
$query = new CGI;
print $query->header;
print $query->start_html('NGD Calculator');
print "<H1>Normalized Google Distance (NGD) Calculator</H1>";

print '<p>';
print 'For information about NGD see Rudi Cilibrasi and Paul Vitanyi, "';
print '<a href="http://www.arxiv.org/PS_cache/cs/pdf/0412/0412098.pdf">';
print 'Automatic Meaning Discovery Using Google</a>."';
print '</p>';

# Print the search box form
print $query->startform;
print '<strong>Enter term 1</strong> ',$query->textfield('term1');
print '<br />';
print '<strong>Enter term 2</strong> ',$query->textfield('term2');
print '<br />';
print $query->submit('form_1','Calculate');
print $query->endform;
print '<br />';

$x = ''; $y = ''; $xy = '';
$x = '+"' . $query->param('term1') . '"';
$y = '+"' . $query->param('term2') . '"';
$xy = $x . " " . $y;

$fx = 1; $fy = 1; $fxy = 1;
$logfx = 0; $logfy = 0; $logfxy = 0; $logm = 0;
$maxlogfxy = 0; $minlogfxy = 0;
$ngd = 0;

# Best guess as of Jan 2006
$m = 11828505634;

if ($x && $y) {

# Determine frequencies
$fx = do_search( $x );
$fy = do_search( $y );
$fxy = do_search( $xy );

# Determine logarithms
$logm = log10( $m );
$logfx = log10( $fx );
$logfy = log10( $fy );
$logfxy = log10( $fxy );

# Determine max and min
@fxy = ($logfx, $logfy);
$maxlogfxy = max @fxy;
$minlogfxy = min @fxy;

# Calculate NGD
$ngd = ($maxlogfxy - $logfxy) / ($logm - $minlogfxy);

print 'NGD(x,y) = ' . $ngd . '<br /><br />';

print 'Term 1: ' . $x . '<br />';
print 'f(x) = ' . $fx . '<br />';
print 'log f(x) = ' . $logfx . '<br /><br />';

print 'Term 2: ' . $y . '<br />';
print 'f(y) = ' . $fy . '<br />';
print 'log f(y) = ' . $logfy . '<br /><br />';

# print 'max(log f(x),log f(y)) = ' . $maxlogfxy . '<br />';
# print 'min(log f(x),log f(y)) = ' . $minlogfxy . '<br /><br />';

print 'Intersection: ' . $xy . '<br />';
print 'f(x,y) = ' . $fxy . '<br />';
print 'log f(x,y) = ' . $logfxy . '<br /><br />';

print 'M: ' . $m . '<br />';
print 'log M: ' . $logm . '<br />';
}

print qq{<P><A HREF="http://history.uwo.ca/faculty/turkel">Digital History at Western</A>};
print $query->end_html;

Please i need some assistance, i am about to use the program for some research project.:confused:
Please can anyone run to program also to verify, please:

Sixtease
01-21-2009, 01:40 AM
Hello spanish,

I tried to run the source you pasted and it compiled fine on my box (after I installed SOAP::Lite, that is). I see some typos in the error messages, so I assume you were manually copying them.

Did you manually copy the source code too? Can we be sure that you run the exactly same code you posted here?

What's your version of perl and of SOAP::Lite? You can check that by running this Perl script:
use SOAP::Lite;
print "Perl version: $]\n";
print "SOAP::Lite version: $SOAP::Lite::VERSION\n";

spanish
01-21-2009, 03:35 AM
Hello,
Thank you very much for your response Sixtease, i am using DzSoft Perl Editor. v5.8.3.7 -iN and also installed SOAP Lite, like you mentioned i got the forms now, with no errors , Thanks.
However the forms are supposed to generate a result when the calculation button is clicked
E.g lets say i enter two terms "egg" term 1 and "fish" term 2, when i click to the calculate button is suppose to produce an answer like :

NGD (x,y) = some value
Term 1: +"egg"
f(x) = some value
logf(x) = s0me value

Term2: +"fish"
f(y)=some value
log f(y) =some value

Intersection: +"egg" + "fish"
f(x,y) = some value
logf(x,y) = some value

M = some value
log M = some value

I dont get any result when the calculate button is clicked, have been trying but can`t.

Thank you

Sixtease
01-21-2009, 03:48 AM
Give us some information on the general setup -- Do you have a webserver where this script is run via CGI? Could you post the HTML that you get from the script? (i.e. the generated page with the form) Does clicking the calculate button reload the page? Is there anything relevant in the server log?

spanish
01-21-2009, 04:12 AM
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>NGD Calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<H1>Normalized Google Distance (NGD) Calculator</H1><p>For information about NGD see Rudi Cilibrasi and Paul Vitanyi, "<a href="http://www.arxiv.org/PS_cache/cs/pdf/0412/0412098.pdf">Automatic Meaning Discovery Using Google</a>."</p><form method="post" action="" enctype="application/x-www-form-urlencoded">
<strong>Enter term 1</strong> <input type="text" name="term1" /><br /><strong>Enter term 2</strong> <input type="text" name="term2" /><br /><input type="submit" name="form_1" value="Calculate" /></form><br />NGD(x,y) = -1.#IND<br /><br />Term 1: +""<br />f(x) = <br />log f(x) = -1.#INF<br /><br />Term 2: +""<br />f(y) = <br />log f(y) = -1.#INF<br /><br />Intersection: +"" +""<br />f(x,y) = <br />log f(x,y) = -1.#INF<br /><br />M: 11828505634<br />log M: 10.072929881069<br /><P><A HREF="http://history.uwo.ca/faculty/turkel">Digital History at Western</A>
</body>
</html>


This is the HTML script that is generated from the script with the form, the page reloads when the calculate button is clicked. but after reloading it appears empty with nothing in the forms
I have Apache server and IIS in my system.

Sixtease
01-21-2009, 04:59 AM
I tried it out and it appears that the script dies silently (which is naughty) when SOAP::Lite-> service($google_wsdl)->doGoogleSearch(@params); fails. Are you certain you put your correct Google key to the $google_key variable? It's assigned to near the top of the script, just beneath the use's.

spanish
01-21-2009, 05:05 AM
Yes, i have the right API keys, do you know of any way to verify the key, i just verified the keys and it is the same API key

Sixtease
01-21-2009, 06:13 AM
I tried to disect it but have failed. I'm experiencing the same behavior like you do and cannot make the goGoogleSearch method dispense any error message or any output at all. In my case the failures are expectable as I have no Google key. I suggest you seek advice from somebody who either has a Google key and has knowledge about Perl or someone involved with the Google API or someone with thorough insight into the SOAP::Lite module.

I'd look at Google developer forums and perlmonks.org . Good luck.

spanish
01-21-2009, 07:20 AM
Thank you so much for the assistance, can i send you my API key so you can try with it, if it`s okay by you

Sixtease
01-21-2009, 07:34 AM
I thought it was bound to a domain, or am I wrong?

spanish
01-21-2009, 10:47 AM
Well i dont know for sure if its for a domain, but here is the it :

ABQIAAAAq8BnDB5aJz60mWC_JluM4xT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRkTxVXeNpC7mBQUY0gn3IXwEK8kw

you can see its possible.

Tanx