How can I use rperl with perlbrew? - perl

I have this simple rperl program:
#!/usr/bin/env perl
use RPerl;
use strict;
use warnings;
our $VERSION = 0.001_000;
# [[[ CRITICS ]]]
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
## no critic qw(ProhibitInterpolationOfLiterals) # USER DEFAULT 3: allow anything
print 'Hello Perl', "\n";
See Exercise 1 in Learning RPerl. I am on Ubuntu 19.04, using perlbrew with perl version 5.28.1. I installed RPerl using:
$ cpanm RPerl
Then I tried to compile the above program:
$ rperl -D p.pl
[...]
[[[ SUBCOMPILE STDERR ]]]
/bin/ld: cannot find -lperl
collect2: error: ld returned 1 exit status
ERROR ECOCOSU04, COMPILER, SUBCOMPILE: C++ compiler returned error code,
[...]

Apparently, rperl needs to link against libperl.so, but the perl I installed rperl with was not built with a shared library libperl.so. The solution was to install a new perl using configure option -Duseshrplib:
$ perlbrew install perl-5.30.0 --notest --noman --as=5.30.0-reloc -Duseshrplib
$ perbrew use 5.30.0-reloc
$ cpanm RPerl
$ rperl -V p.pl
[...]
$ ./p
Hello Perl

Related

Perl Compiling PP issue in Strawberry Perl [duplicate]

I've been using pp
https://metacpan.org/pod/pp
A while ago!
However when hiring another hosting, when I run the pp command the scripts do not run on the server
CentOS Linux release 7.9.2009 (Core)
Perl v 5.32.1
Command using pp, host old
$ pp -x -c name.pl
When running
./a.out
Unable to open html entities file (/tmp/par-726f6f74/cache-78cdefedff4d2afddea0035addc3b570c8f0bfd5/inc/lib/Mojo/resources/html_entities.txt): No such file or directory at script / name.pl line 13.
Compilation failed in require at script / name.pl line 13.
BEGIN failed - compilation aborted at script / name.pl line 13.
And when I run ./name.pl it runs normally.
Any suggestion?
name.pl
#!/usr/bin/perl
use FindBin qw($Bin);
use lib ("$Bin");
use DBI;
use Number::Format;
use Encode qw(decode encode);
use File::Basename;
use Mojo::Util qw(b64_encode b64_decode url_escape url_unescape);
use Mojo::JSON qw(decode_json encode_json);
use Image::ExifTool;
use LWP;
print "Test Mojo";
This same command works normally in version 5.28 on another server/hosting
You need to add the file html_entities.txt to the archive.
The following seems to work for me:
Find the location of the file:
$ perl -MMojo::Util -MFile::Basename=dirname -E '$fn = (dirname $INC{"Mojo/Util.pm"}) . "/resources/html_entities.txt"; say $fn'
/home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Mojo/resources/html_entities.txt
Copy the file to a local directory:
$ mkdir -p ./lib/Mojo/resources/
$ cp /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Mojo/resources/html_entities.txt ./lib/Mojo/resources/
Add the file to the archive
$ pp -x -c -a lib/Mojo/resources/html_entities.txt name.pl

No run time & compile time error in Perl

I am trying to execute the following small script.
test.pl
#!/bin/perl
use strict;
$value = 1;
The output is
perl -c test.pl
test.pl syntax OK
Please let me know why it is not throwing error?
Thanks in advance.
What version of Perl are you using? This is Perl 5.18:
$ cat test1.pl
#!/bin/perl
use strict;
$value = 1;
$ perl -c test1.pl
Global symbol "$value" requires explicit package name at test1.pl line 3.
test1.pl had compilation errors.
I get the error.
Is it possible you're not running against the Perl script you think you are?

Error: Can't locate File/HomeDir.pm in #INC

I use a Mac OS X 10.8, and want to run the latexindent.pl perl script on my latex files. This script is made by https://github.com/cmhughes/latexindent.plx. When I run this script on a latexfile I get this error message:
Can't locate File/HomeDir.pm in #INC (#INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4/darwin-thread-multi-2level /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at helloworld.pl line 10.
BEGIN failed--compilation aborted at helloworld.pl line 10.
It seems that I am missing the File::HomeDir module in perl so I tried to download it using:
sudo perl -MCPAN -e 'install File::HomeDir',
I get the following error:
Can't locate object method "install" via package "File::HomeDir".
I managed to install the YAML::Tiny package without any problems.
I tried to run:
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use FindBin;
6 use YAML::Tiny;
7 use File::Copy;
8 use File::Basename;
9 use Getopt::Std;
10 use File::HomeDir;
11
12 print "hello world";
13 exit;
and got the same Error message as above...
Do anyone know what to do?
sudo perl -MCPAN -e 'install "File::HomeDir"'
^ ^
I had a similar problem. I just ran these commends, and it worked for me
sudo cpan -i File::HomeDir
then
sudo cpan -i Unicode::GCString
Basically, I will run latexindent file_name.tex, then an error message will appear that says you may need to install the XXXX module then I install the XXXX module using sudo cpan -i XXXX

How can I know where a Perl module is installed?

I want to know where the IO::Socket::SSL module, or more specifically, where the file SSL.pm is located. I already know that I have installed IO::Socket::SSL because use IO::Socket::SSL works.
I always use something like this:
%> perl -MIO::Socket::SSL -e 'print $INC{"IO/Socket/SSL.pm"}';
and you get the path or an error if the module it is not installed in a proper path where perl can get it.
If you want to see if that module was installed:
%> perl -MIO::Socket::SSL -e 1
if you don't get any error, it's installed.
Sometimes it's important to see the version number of the installed package:
%> perl -MIO::Socket::SSL -e 'print $IO::Socket::SSL::VERSION';
Or, if you are working on Windows, you have to use double-quotes:
C:\> perl -MIO::Socket::SSL -e "print $IO::Socket::SSL::VERSION";
This should work
perldoc -l 'IO::Socket::SSL'
or alternatively in cmd.exe
perldoc -l "IO::Socket::SSL"
-l switch means "Display the module's file name". I find that it shows the fully qualified path to a module or (if applicable) to the module's external POD which is in the same directory as the module itself.
You can do:
perl -E'use IO::Socket::SSL; say $INC{"IO/Socket/SSL.pm"};'
But a rule of thumb it most modules are typically in /usr/share/perl5 on ubuntu.
The pmtools package provides an assortment of useful command line utils for finding where a package is installed (pmpath), what version it is at (pmvers), etc

How to get the default encoding of current OS in perl script?

How can I get the default encoding used by current platform?
Is there any available module in CPAN or with the distribution of Perl itself?
I can't find the solution in perl.org
See I18N::Langinfo.
$ LANG=en_US.UTF-8 perl -MI18N::Langinfo=langinfo,CODESET -E 'say langinfo(CODESET())'
UTF-8
$ LANG=C perl -MI18N::Langinfo=langinfo,CODESET -E 'say langinfo(CODESET())'
ANSI_X3.4-1968
$ LANG=ja_JP.eucjp perl -MI18N::Langinfo=langinfo,CODESET -E 'say langinfo(CODESET())'
EUC-JP
This is probably what you're looking for. If you follow the code in I18N::Langinfo, you can see how it discovers what locale to use for returning this.