WWW::Mechanize::Firefox -- connection tme out - perl

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.

Related

Command for login history in Strawberry Perl in Windows

I am getting error i.e last is not recognized as a internal or external in cmd prompt
What I have tried:
#!/usr/bin/perl
use strict;
use warnings;
my $d=system("last");
print $d;
You can't use the last command under windows, you'll have to use something like wmic, net user or similar, depending on what info you need/want.

Undefined subroutine &main::key_enc

I have a Perl module named McuEnc.pm which is located at /home/eric/temp directory:
package McuEnc;
use 5.010;
use strict;
use warnings;
use Exporter qw(import);
our #EXPORT_OK = qw(key_enc data_enc data_dec);
sub key_enc { some code }
sub data_enc { some code }
sub data_dec { some code }
1;
I have a Perl script named test.pl which is also located at /home/eric/temp directory:
use 5.010;
use strict;
use warnings;
use McuEnc qw(key_enc data_enc data_dec);
key_enc("1111");
...
I have changed working directory to /home/eric/temp. Now if I run test.pl script, it runs correctly. But if I create a new directory /home/eric/temp/My and move the McuEnc.pm file into it and then modify the test.pl script as follwoing:
use 5.010;
use strict;
use warnings;
use My::McuEnc qw(key_enc data_enc data_dec);
key_enc("1111");
...
then I'm getting the following error when I run test.pl again:
Undefined subroutine &main::key_enc called at ./test line 6.
However, I can still call the subroutine correctly with:
McuEnc::key_enc("1111");
So why I'm getting the error message? what is wrong?
This was answered by Sobrique in the comments, but it was never posted as an official answer:
"The use statement doesn't match the package statement. Try package My::McuEnc instead"

Autodie fools syntaxcheck of perl

Seems as if depending on the version of perl, autodie masks some syntax-errors.
In Perl 5.16.0:
$ perlbrew use 5.16.0
$ perl -c check_netapp_pro/lib/Il/Nagios/test/xx.pm
String found where operator expected at check_netapp_pro/lib/Il/Nagios/test/xx.pm line 10, near "croak "stop""
(Do you need to predeclare croak?)
syntax error at check_netapp_pro/lib/Il/Nagios/test/xx.pm line 10, near "croak "stop""
check_netapp_pro/lib/Il/Nagios/test/xx.pm had compilation errors.
But in 5.10.1:
$ perlbrew use 5.10.1
$ perl -c check_netapp_pro/lib/Il/Nagios/test/xx.pm
check_netapp_pro/lib/Il/Nagios/test/xx.pm syntax OK
The module xx.pm is:
package Il::Nagios::Store::Attribute;
use feature ':5.10';
use strict;
use warnings;
use autodie;
#use Carp;
croak "stop" if 0;
1;
__END__
The confusing part is that on some servers (e.g. CentOS 6.5, perl 5.10.1) the absence of use Carp; stops script execution even if use autodie; is present in the module.
Can anyone shed some light on this? How would you unit-test against such errors? (Test::Strict did not detect the missing use Carp; statement).
Thanks to the comment from #i-alarmed-alien I could quickly determine the reason:
On my 5.10.1 perlbrew installation autodie is installed with version 2.06_01, the newer installation (perl 5.16.0) is using autodie in version 2.10 where a bug had been fixed, which leaked the Carp functions.
Just for the records: To determine the version of autodie (or any other module) just type
cpan -D autodie

How can one respond to the --help flag with Getopt::Std?

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

Perl: how to fix SOAP::Lite delcampe-api-client example?

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();