wikiprep syntax error: Use of the encoding pragma is deprecated - perl

I am trying to use wikiprep (https://github.com/avian2/wikiprep) to parse wikipedia dump (in Feb 2014) and generate a XXX.hgw.xml file from the dump.
I followed the usage on Github site above: installed all Perl modules as prerequisites; Build and install wikiprep successfully (wikiprep program appeared in perl5/bin directory). When I execute wikiprep, it says:
Use of the encoding pragma is deprecated at /home/tutran/perl5/bin/wikiprep line 32.
Use of the encoding pragma is deprecated at /home/tutran/perl5/lib/perl5/Wikiprep/languages.pm line 7.
syntax error at /home/tutran/perl5/lib/perl5/Wikiprep/Disambig.pm line 9, near "->import qw/ extractWikiLinks /"
Compilation failed in require at /home/tutran/perl5/bin/wikiprep line 52.
BEGIN failed--compilation aborted at /home/tutran/perl5/bin/wikiprep line 52.
This the line 9:
Wikiprep::Link->import qw/ extractWikiLinks /;
Expected output: options I can use with wikiprep. I also cannot make test for the program. I installed it on Ubuntu 14.04 LTS. My Perl version is 5.18.02.
I don't know anything about perl language so I can't do anything with the "syntax error" here!

You may need enable ut8 in your script. PLace this two lines before you start using this module:
use utf8;
use open qw( :encoding(cp866) :std );

In /usr/local/bin/ wikiprep change line 135 i'e (Wikiprep::Templates->import qw( %templates includeTemplates );) to :
Wikiprep::Templates->import(qw( %templates includeTemplates ));
and
in file
/usr/local/share/perl/5.18.2/Wikiprep/Disambig.pm
change
Wikiprep::Link->import qw/ extractWikiLinks /; to
Wikiprep::Link->import(qw/ extractWikiLinks /);

Related

perl module Class::HPLOO v0.23 install issue #2

Having the exact issue as described at: perl module Class::HPLOO v0.23 install issue, I have attempted to correct the defined(#array) problem by editing to just (#array) and trying to rebuild the module. However I continue to get the return of:
$ make clean
$ perl Makefile.PL
$ make
$ make test: *** No rule to
make target `clean:'. Stop. Manifying 2 pod documents
PERL_DL_NONLAZY=1 "/opt/local/bin/perl5.26" "-Iblib/lib" "-Iblib/arch"
test.pl
1..42
# Running under perl version 5.026002 for darwin
# Current time local: Sun Aug 26 06:48:26 2018
# Current time GMT: Sat Aug 25 22:48:26 2018
# Using Test.pm version 1.26 not ok 1
# Failed test 1 in test.pl at line 9
# test.pl line 9 is: ok(!$#) ; Can't locate object method "new" via package "Foo" at test.pl line 11. make: *** [test_dynamic] Error 2
There are three issues with Class::HPLOO (which as I noted before, hasn't been updated since 2005) that make it fail with modern perls.
As discovered in the previous post,
the obsolete construct defined (#array) is used once in lib/Class/HPLOO.pm' and three times inlib/Class/HPLOO/Base.pm`. This construction has been prohibited since v5.22
The current directory (.) is no longer in #INC (as of v5.24, I think). So the lines in test.pl like
require "test/classtest.pm"
either all need to be rewritten as
require "./test/classtest.pm"
or an easier fix is to put
use lib '.';
at the top of the script.
There is a regular expression in lib/Class/HPLOO.pm, line 1077, with an "unescaped left brace"
$sub =~ s/(\S)( {) (\S)/$1$2\n$FIRST_SUB_IDENT $3/gs ;
{ is a regex metacharacter, and since v5.22 it has been illegal to use it in a context where it is not indicating a quantity. The fix, as the error message suggests, is to escape it.
$sub =~ s/(\S)( \{) (\S)/$1$2\n$FIRST_SUB_IDENT $3/gs ;
Make these three changes to the code you download from CPAN and the module should build on modern Perls. If you're feeling helpful, you can submit a bug report (linking to this post, if you want) or even a patch with an email to bug-Class-HPLOO#rt.cpan.org
come across this issue today, so I fixed it following the answer above. if anyone want to save some time.
I create a repo with the changes. https://github.com/swuecho/Class_HPLOO.git

Installed module not found when running program

Context
Here is a perl test script, in which I wanted to see how you can use a specific event loop with AnyEvent :
# file test.pl :
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Impl::EV;
my $cv = AnyEvent->condvar;
my $wait_one_and_a_half_seconds = AnyEvent->timer (
after => 0.5, # after how many seconds to invoke the cb?
cb => sub { # the callback to invoke
print ("Hello from callback\n");
$cv->send;
},
);
# now wait till our time has come
$cv->recv;
Problem
Here is the error I get when running the above code :
$ perl test.pl
Can't locate EV.pm in #INC (you may need to install the EV module) (#INC
contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2
/usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18
/usr/local/lib/site_perl .) at /usr/local/lib/perl/5.18.2/AnyEvent/Impl/EV.pm
line 28.
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.18.2/AnyEvent/Impl/EV.pm line 28.
Compilation failed in require at test.pl line 6.
BEGIN failed--compilation aborted at test.pl line 6.
Yet I installed the AnyEvent package using cpanm, and the AnyEvent/Impl/EV.pm file is present in one of the #INC path :
$ ls /usr/local/lib/perl/5.18.2/AnyEvent/Impl/
Cocoa.pm Event.pm FLTK.pm IOAsync.pm Perl.pm Qt.pm UV.pm
EventLib.pm EV.pm Glib.pm Irssi.pm POE.pm Tk.pm
Question
How do I fix this ?
Extra remark
The error message says it is looking for EV.pm, but I would have expected AnyEvent/Impl/EV.pm.
How come the use AnyEvent::Impl::EV; I wrote got turned into perl is looking for EV.pm at runtime ?
Just tried to reproduce this with cpan install AnyEvent and can confirm I get the same error.
Line 28 of 'EV.pm' is use EV 4.00;. Your use EV; is a bit of a red herring - that's not the source of the error. This module explicitly includes a 'use' line (which frankly is a bit wierd, it's 'using' itself it seems?)
I don't think that's ever going to work, unless the #INC path is changed - I can only assume that the loading of this module is handled elsewhere, without deconstructing source code.
Referencing the man page - this module gets loaded automatically as required. So you probably don't need to use it in the first place.
Edit: Just compared perl versions. Perl 5.8.5 shows the same behaviour. My 5.20.1 install doesn't.
I'm not sure upgrading perl is necessarily the right step, but it might be worth trying? I'll try and figure out why 5.20.1 works though. It's got to be something to do with handling of #INC.
Edit:
"The handling of return values of #INC filters (subroutines returned by subroutines in #INC) has been fixed in various ways. Previously tied variables were mishandled, and setting $_ to a reference or typeglob could result in crashes."
http://perldoc.perl.org/perl5200delta.html
I think that might be what the problem is.
You're certainly not alone in having this:
http://www.cpantesters.org/cpan/report/d5939816-a510-11e0-bd04-22322d9f2468
From:
http://cpansearch.perl.org/src/MLEHMANN/AnyEvent-7.08/Changes
5.29 Sun Dec 5 10:49:21 CET 2010
- convert EV backend to EV 4.00 API (so better upgrade EV too).
The error message was actually a very correct and forward pointer to what should be done : there is an EV package which needs to be installed separately :
$ sudo cpanm EV
--> Working on EV
Fetching http://www.cpan.org/authors/id/M/ML/MLEHMANN/EV-4.18.tar.gz ... OK
Configuring EV-4.18 ... OK
Building and testing EV-4.18 ... OK
Successfully installed EV-4.18
1 distribution installed
After that, everything works :
$ cat test.pl
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
use EV;
my $wait_one_and_a_half_seconds = AnyEvent->timer (
after => 0.5, # after how many seconds to invoke the cb?
cb => sub { # the callback to invoke
print ("Hello from callback\n");
},
);
# now wait till our time has come
EV::run();
$ perl test.pl
Hello from callback

Errors using Parallel::ForkManager

I'm trying to run a Perl script that uses Parallel::ForkManager:
#!/usr/bin/perl
use Parallel::ForkManager;
use LWP::Simple;
my $pm= Parallel::ForkManager->new(10);
for my $link (#ARGV) {
$pm->start and next;
my ($fn)= $link =~ /^.*\/(.*?)$/;
if (!$fn) {
warn "Cannot determine filename from $fn\n";
}
else {
$0.=" ".$fn;
print "Getting $fn from $link\n";
my $rc=getstore($link,$fn);
print "$link downloaded. response code: $rc\n";
};
$pm->finish;
};
But I get the following errors:
File::Path version 2.06 required--this is only version 1.08 at /usr/lib/perl5/5.8.8/File/Temp.pm line 14.
BEGIN failed--compilation aborted at /usr/lib/perl5/5.8.8/File/Temp.pm line 14.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Parallel/ForkManager.pm line 441.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/Parallel/ForkManager.pm line 441.
Compilation failed in require at parallel.pl line 3.
BEGIN failed--compilation aborted at parallel.pl line 3.
How can I resolve them?
Upgrade your version of File::Path.
As the error says, you're running version 1.08, but the version of ForkManager that you're running is dependent upon version 2.06.
Note also, that it appears that it is actually File::Temp, which has the File::Path dependency, while P::FM has a dependency on File::Temp.
Either way, you need a more recent version of File::Path.
Perl 5.8.8 is from 2006. Upgrade to a supported version

What's wrong with this Perl module?

I am making a very, very simple module (it is the first I've ever wrote):
package Master::Math;
use 5.12.4;
use strict;
use warnings;
require Exporter;
our #ISA = qw(Exporter)
our %EXPORT_TAGS = (
'all' => [ qw(
max
=cut
1; # End of Master::Math
When I run use this in my program, I get the error
Invalid version format (non-numeric data) at C:/Perl/lib/Master/Math.pm line 3,
near "package Master::Math
"
syntax error at C:/Perl/lib/Master/Math.pm line 3, near "package Master::Math
require Exporter"
Compilation failed in require at C:\MainDev\myperl\max.pl line 3.
BEGIN failed--compilation aborted at C:\MainDev\myperl\max.pl line 3.
What do I need to fix this? Thanks!
You're missing a semicolon on the declaration of #ISA.
In sub max, $foo is undeclared; use foreach my $foo ....
That should get it to compile. I haven't looked beyond that.
(BTW, I didn't get the same errors you did. I used perl 5.14.0, perl -cw master-math.pm.)

Why do I get "version (5.12.2) doesn't match executable version" with Perl's PAR?

When I run the following to create an executable out of my Perl script:
pp -o process_target_mode_data Process_Target_Mode_Data.pl
I get the following error output:
Perl lib version (5.12.2) doesn't match executable version (v5.12.0) at /home/Neil/ActivePerl-5.12/lib/Config.pm line 50.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
Compilation failed in require at -e line 459.
/home/Neil/ActivePerl-5.12/site/bin/pp: Failed to extract a parl from 'PAR::StrippedPARL::Static' to file 'parleNrP2Xi' at /home/Neil/ActivePerl-5.12/site/lib/PAR/Packer.pm line 1172, <DATA> line 1.
Could someone explain to me what is going on and how I can resolve this problem?
Info brian d foy requested:
[bash-3.2][Neil#willy]$ which pp
/home/Neil/ActivePerl-5.12/site/bin/pp
[bash-3.2][Neil#willy]$ /home/Neil/ActivePerl-5.12/site/bin/pp -o process_target_mode_data Process_Target_Mode_Data.pl
Perl lib version (5.12.2) doesn't match executable version (v5.12.0) at /home/Neil/ActivePerl-5.12/lib/Config.pm line 50.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
Compilation failed in require at -e line 459.
/home/Neil/ActivePerl-5.12/site/bin/pp: Failed to extract a parl from 'PAR::StrippedPARL::Static' to file 'parludZfldz' at /home/Neil/ActivePerl-5.12/site/lib/PAR/Packer.pm line 1172, line 1.
[bash-3.2][Neil#willy]$
[bash-3.2][Neil#willy]$ /home/Neil/ActivePerl-5.12/bin/cpan -l | grep PAR
PAR 1.002
PAR::Dist 0.47
PAR::Heavy 0.12
PAR::Filter 0.03
PAR::SetupTemp 1.002
PAR::SetupProgname 1.002
PAR::Packer 1.006
PAR::StrippedPARL::Dynamic 0.958
PAR::StrippedPARL::Static 0.958
PAR::StrippedPARL::Base 0.975
PAR::Filter::Bytecode undef
PAR::Filter::Bleach undef
PAR::Filter::Obfuscate undef
PAR::Filter::PatchContent undef
PAR::Filter::PodStrip undef
App::Packer::PAR 0.91
Perl lib version (5.12.2) doesn't match executable version (v5.12.0)
Some parts of your Perl installation are at a different version than others. More specifically, if you look at /home/Neil/ActivePerl-5.12/lib/Config.pm line 50, you will see that there is an explicit comparison of the version of Perl being executed (which is 5.12.0) to the version of the Config.pm library being used (5.12.2).
If you perform a new installation of ActivePerl 5.12.2 (to bring all components up to the same version), this error should go away.
I had same issue. I installed PAR::Packer from Activestate Perl Package Manager (PPM). As mentioned above in one of the replies, there is version mismatch between the perl and pp binaries. Here's how I fixed it:
Uninstall PAR-Packer from PPM.
Open DOS command line.
Run cpan install PAR::Packer
This will download, compile, and install the package from CPAN. MinGW compiler toolchain will be downloaded as well, if needed. The whole process may take a while on slower cpus.
Find the location of that pp, then figure out its version. I bet it's left over from an earlier installation. Ensure that you have PAR for your new version of Perl.
You can also try specifying the location of the particular pp you want to use so you know exactly what one you are using:
$ /full/path/to/5.12.2/pp ...
Go to the perl/lib/Config.pm and changed the condition in the lines:
die "$0: Perl lib version (5.32.0) doesn't match executable '$^X' version ($])" unless $^V;
to
die "$1: Perl lib version (5.32.1) doesn't match executable '$^X' version ($])" unless $^V;
and the next line
$^V eq 5.32.0 or die sprintf "%s: Perl lib version (5.32.0) doesn't match executable '$^X' version (%vd)", $0, $^V;
to
$^V eq 5.32.1 or die sprintf "%s: Perl lib version (5.32.1) doesn't match executable '$^X' version (%vd)", $0, $^V;
this worked for me, at least it won't complain... yes, i know, PERL and Python are f***d up.