Here http://code.google.com/p/delcampe-api-client/wiki/Info#Perl is code example of delcampe-api-client in Perl. Obviously, there is an syntax error, running the code i got:
syntax error at test.pl line 9, near "-> service"
Bareword "SOAP::Lite" not allowed while "strict subs" in use at test.pl line 8.
Execution of test.pl aborted due to compilation errors.
If i change code to little bit more meaningful for me, like this:
#!/usr/bin/perl
use SOAP::Lite;
use SOAP::WSDL;
use strict;
use warnings;
my $service = new SOAP::Lite;
print $service
->uri('http://api.delcampe.net/soap.php?wsdl')
->getServerTime()
->result;
I got:
A service address has not been specified either by using SOAP::Lite->proxy() or a service description)
What is wrong with this code? What proxy? Service description?
[ If you think, i have no experience with SOAP, you are certainly right. Still, how to get this little example to work. PHP example worked nicely, but not the Perl's one. ]
If I were you, I would give "The Fine Documentation" a try. This should work, however:
#!/usr/bin/perl
use SOAP::Lite;
use SOAP::WSDL;
use strict;
use warnings;
my $service = SOAP::Lite->service('http://api.delcampe.net/soap.php?wsdl');
print $service->getServerTime()->result;
Edit:
Documentation can be found at http://guide.soaplite.com/ - also perldoc SOAP::Lite from the command line.
The example (above) on the web site appears not to work on more than one count: this one, however, is tested and works on my machine:
#!/usr/bin/perl
use SOAP::Lite;
use strict;
use warnings;
my $service = SOAP::Lite->service('http://api.delcampe.net/soap.php?wsdl');
print $service->getServerTime();
Related
I've moved part of a script into a module, and now the only error I get when I do something wrong is "Undefined subroutine", even when the real error is that I misspelled a variable, or forgot a closing paren, or left off a semi-colon.
The only way to find the real error is to copy the entire thing into a script and run it that way. It's very tedious. Am I doing something wrong, or is this just the way modules are supposed to work?
Here is a very simple example that shows the problem:
Module:
#!/usr/bin/env perl
package CalledError;
use Exporter qw(import);
our #EXPORT_OK=qw(do_build_stor_pools);
use strict;
use warnings;
use feature qw(say);
sub do_build_stor_pools {
say "now in CalledError do_build_stor_pools";
#my $undef_var="uncomment this to fix";
say $undef_var;
return;
}
Calling script:
#!/usr/bin/env/perl
use strict;
use warnings;
my $buildstor_mod="CalledError";
eval "require $buildstor_mod";
$buildstor_mod->import();
CalledError::do_build_stor_pools();
Run it like this to get
Undefined subroutine &CalledError::do_build_stor_pools called at calling_test.pl line 11.
Uncomment the definition of $undef_var to make it work.
If you checked $EVAL_ERROR, you would see the real error:
#!/usr/bin/env/perl
use strict;
use warnings;
my $buildstor_mod="CalledError";
eval "require $buildstor_mod";
if ($#) {
die "$#";
}
$buildstor_mod->import();
CalledError::do_build_stor_pools();
Error message:
Global symbol "$undef_var" requires explicit package name at CalledError.pm line 15.
Compilation failed in require at (eval 1) line 2.
You see the undefined subroutine error because require fails.
You're not checking the error condition of your eval:
eval "require $buildstor_mod";
die $# if $#;
However, to load a module, you should just use use:
use strict;
use warnings;
use CalledError qw(do_build_stor_pools);
do_build_stor_pools();
Outputs:
Global symbol "$undef_var" requires explicit package name at CalledError.pm line 14.
I want my script to print a help message when it is run with the --help command line option. Based on the Getopt::Std documentation, this sub should do the trick:
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use Getopt::Std;
sub HELP_MESSAGE {
say "HELP MESSAGE";
}
But it prints nothing. I also tried adding this, out of curiosity:
for (#ARGV) {
HELP_MESSAGE() if /--help/;
}
It actually works, but seems rather sloppy. I know using the -h flag would be quite simple, but I would like to have both.
The documentation of Getopt::Std says
If - is not a recognized switch letter, getopts() supports arguments --help and --version. If main::HELP_MESSAGE() and/or main::VERSION_MESSAGE() are defined, they are called; ...
So try this:
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
our $VERSION = 0.1;
getopts(''); # <<< You forgot this line, and `getopt()` DOES NOT work
sub HELP_MESSAGE {
say "HELP MESSAGE";
}
Test run:
$ ./t00.pl --help
./t00.pl version 0.1 calling Getopt::Std::getopts (version 1.07),
running under Perl version 5.16.3.
HELP MESSAGE
I use perl version 5.14.2 (I think active) on a windows 32 machine with firefox version 18.
I'm trying to run the following code:
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $mech = WWW::Mechanize::Firefox->new(
activate => 1, # bring the tab to the foreground
);
$mech->get('https://familysearch.org/search/collection/results#count=20&query=%2Bevent_place_level_1%3ACalifornia%20%2Bevent_place_level_2%3A%22San%20Diego%22%20%2Bbirth_year%3A1923-1923~%20%2Bgender%3AM%20%2Brace%3AWhite& collection_id=2000219',':content_file'
'main.html');
1;
I get the error:
command timed-out at C:/Perl/site/lib/MozRepl/Client.pm line 186
I would greatly appreciate any help fixing this error.
However, if I run the following, it works:
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
Under Tool, I see MozRepl. I clicked ActivateStart.
I am trying to move existing perl files to a new server and I am getting an error (error_log file). It work on the old server.
When I access to: http://2x.29.xx.xx/admin/web.pl
I get an error:
[error] Undefined subroutine &web_main::main called at
/var/www/path/web.pl line 40.
web.pl file, it look something like this:
#!/usr/bin/perl -w
use strict;
use warnings;
use lib '/var/www/web';
our $var = '/var/www/web';
our $var1;
our $var2;
use web_main qw($var $var1 $var2);
web_main::main(); # Line 40
web_main.pm file (in /var/www/web), look something like this:
#!/usr/bin/perl -w
package web_main;
use strict;
use warnings;
sub main
{
# Lots of code here... removed for brevity
}
Not sure what went wrong?
I'm not really an expert in Perl but perhaps you need to export the main subroutine? You can use Exporter.
I have a failing test on 5.8.8, I don't understand why, esp when it works in more recent versions (perhaps it was just a bug) (here's a link to the full code)
use strict;
use warnings;
use Test::More;
my $fname = 'Fo';
my $content = do { local $/ ; <DATA> };
like $content, qr/^$fname $/xms, q[includes first name];
done_testing;
__DATA__
use strict;
use warnings;
use Test::More;
# generated by Dist::Zilla::Plugin::Test::PodSpelling bootstrapped version
eval "use Test::Spelling 0.12; use Pod::Wordlist::hanekomu; 1" or die $#;
add_stopwords(<DATA>);
all_pod_files_spelling_ok('bin', 'lib');
__DATA__
Fo
oer
bar
on all recent versions of perl this works fine. but in 5.8.8 the test fails. I found that by removing the ^ and $ the code works, its like Perls regex engine is ignoring the /m but the documentation says it was supported.
Why does this not work? and what is the most correct way to fix it? (note: I believe that the test should check that these elements are on a line by themselves )
This is bug RT#7781. It was fixed in 5.8.9 and 5.10.0.
Workarounds:
qr/^/m is equivalent to qr/(?:^|(?<=\n))/
qr/$/m is equivalent to qr/(?=\n|\z)/