0
votes

I am trying to run a perl script 'googly.pl' from the command line, and it is giving some errors. Here is the script and the errors. I have re-checked the script, but I am still unable to successfully run the script.

#!C:\Strawberry\perl\bin\perl.exe
# googly.pl
# A typical Google Web API Perl script
# Usage: perl googly.pl <query>
# Your Google API developer's key
my $google_key='';
# Location of the GoogleSearch WSDL file
my $google_wdsl = "C:/vhosts/phpcs5/GoogleSearch.wsdl";
use strict;
# Use the SOAP::Lite Perl module
use SOAP::Lite;
# Take the query from the command-line
my $query = shift @ARGV or die "Usage: perl googly.pl
<query>\n";
# Create a new SOAP::Lite instance, feeding it
GoogleSearch.wsdl
my $google_search = SOAP::Lite->service("file:$google_wdsl");
# Query Google
my $results = $google_search ->
doGoogleSearch(
$google_key, $query, 0, 10, "false", "", "false",
"", "latin1", "latin1"
);
# No results?
@{$results->{resultElements}} or exit;
# Loop through the results
foreach my $result (@{$results->{resultElements}}) {
# Print out the main bits of each result
print
join "\n",
$result->{title} || "no title",
$result->{URL},
$result->{snippet} || 'no snippet',
"\n";
}

Errors

  1. Semicolon seems to be missing at C:/vhosts/phpcs5/googly.pl line 19.
  2. Syntax error at C:/vhosts/phpcs5/googly.pl line 17, near "wsdl my "
  3. Global symbol "$google_search" requires explicit package name at C:/vhosts/phpcs5/googly.pl line 17
  4. Global symbol "$google_search" requires explicit package name at C:/vhosts/phpcs5/googly.pl line 19
  5. Syntax error at C:/vhosts/phpcs5/googly.pl line 20, near "doGoogleSearch"
  6. Execution of C:/vhosts/phpcs5/googly.pl aborted due to compilation errors.
1
Seems like you've pasted it from somewhere, introducing new lines where they shouldn't be. - slim
in addition to below given answer ther is a suggestion u can set the "C:\Strawberry\perl\bin\perl.exe" in the environment variable and the use it. Also put the semi-colons wherever required. - pkm
@ashish: The shebang line of a Perl program has no effect on Windows, except that any command line switches are honoured. Windows doesn't use it to locate the Perl executable. In fact the shell won't handle anything but shell command files. - Borodin
@borodin: i thought it takes the path of perl from the environment variable that is what is mentioned is it wrong?? - pkm
@ashish: I don't think so. Where did you read that? If you use cmd.exe to run a program.pl file (or double-click it in explorer) then it will check the registry to see which executable handles such files and hand it over if it finds one. If it doesn't then it tells you it can't run the file. The Perl compiler will look at various environment variables once it starts running, but I don't think any environment variables dictate which Perl compiler to run. Please correct me if I'm wrong. - Borodin

1 Answers

4
votes
my $query = shift @ARGV or die "Usage: perl googly.pl
<query>\n";
# Create a new SOAP::Lite instance, feeding it
GoogleSearch.wsdl
my $google_search = SOAP::Lite->service("file:$google_wdsl");

should be

my $query = shift @ARGV or die "Usage: perl googly.pl <query>\n";
# Create a new SOAP::Lite instance, feeding it GoogleSearch.wsdl
my $google_search = SOAP::Lite->service("file:$google_wdsl");