Installing the Modern::perl module via CPAN
Please help me figure out where CPAN installs modules, I'm just starting to learn perl and I'm not very good at using it. In particular, using the say command instead of print requires using the Moder::perl module
Let's say there is a file:
~/perl$ cat ./34
#!/usr/bin/perl
use Modern::Perl;
say "34";
Which gives the following output:
$ ./34
Can't locate Modern/Perl.pm in @INC (you may need to install the
Modern::Perl module) (@INC contains: /etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base .) at ./34 line 2.
BEGIN failed--compilation aborted at ./34 line 2.
The corresponding module was downloaded using CPAN. In general, the module was downloaded after the install Modern command::Perl
Since the output is it turned out to be the same, the following method was used:
~/.cpan/build/Modern-Perl-1.20170117-ZIYFay$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Modern::Perl
Writing MYMETA.yml and MYMETA.json
~/.cpan/build/Modern-Perl-1.20170117-ZIYFay$ make
Skip blib/lib/Modern/Perl.pm (unchanged)
Manifying 1 pod document
:~/.cpan/build/Modern-Perl-1.20170117-ZIYFay$ make test
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-
MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0,
'blib/lib', 'blib/arch')" t/*.t
t/base.t .......... ok
t/regressions.t ... ok
t/unimport.t ...... ok
t/year_imports.t .. ok
All tests successful.
Files=4, Tests=88, 1 wallclock secs ( 0.03 usr 0.01 sys + 0.15 cusr 0.03 csys = 0.22 CPU)
Result: PASS
After that, the same file was run again. /34:
~/perl$ ./34
Can't locate Modern/Perl.pm in @INC (you may need to install the
Modern::Perl module) (@INC contains: /etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base .) at ./34 line 2.
BEGIN failed--compilation aborted at ./34 line 2.
As a result, the following list file was compiled, containing all the paths from the error:
~/perl$ for i in `cat list`; do echo $i ; done
/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22
/usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base
Which I ran through with the find command, in order to find the word Modern in the specified paths, the result was sludeyuschim:
$ for i in `cat list`; do find $i -name '*Modern*' ; done
find: «/usr/local/lib/x86_64-linux-gnu/perl/5.22.1»: Нет такого файла или каталога
find: «/usr/local/share/perl/5.22.1»: Нет такого файла или каталога
find: «/usr/local/lib/site_perl»: Нет такого файла или каталога
При этом:
~/perl$ perl -wE 'say 34'
34
The essence of the question, please help me figure out how I can start using the say and other commands from the 5.10 version in my scenarios.
3 answers
You don't need to install anything. Say (and others) is enabled automatically if you switch to Pearl 5.10. Add "use v5. 10;"to the script. You can activate this feature separately: "use feature 'say';".
And why go into the wilds and put the module with handles? This is all already automated.
To do this, use the command cpan
or a more modern version of cpanm
:
cpan Modern::Perl
The module is installed in the system and therefore may require sudo.
To install the module in your own folders, you need to configure the environment variables:
export PERL_MB_OPT="--install_base \"/home/$(whoami)/perl5\""
export PERL_MM_OPT="INSTALL_BASE=/home/$(whoami)/perl5"
And in order for pearl to see (know where to look for your modules), you need to install PERL5LIB
:
export PERL5LIB='/home/$(whoami)/perl5/lib/perl5'
These the commands you need to put in your ~/.bash_aliases
But now I'm doing it all through perlbrew
. This is a more modern way.
You can install it like this:
$ \wget -O - https://install.perlbrew.pl | bash
And also for convenience, add to ~/.bash_aliases
:
if [ -f ~/perl5/perlbrew/etc/bashrc ]; then
source ~/perl5/perlbrew/etc/bashrc
source ~/perl5/perlbrew/etc/perlbrew-completion.bash
alias pb="perlbrew"
complete -F _perlbrew_compgen pb
fi
Next, see which perl
are available, choose:
$ perlbrew available
And put:
$ perlbrew install perl-5.26.1
Don't forget to switch to it:
$ perlbrew switch perl-5.26.1
$ perl -v
It is worth mentioning that after installation, you will have a folder in your home directory ~/perl5
. There will be put all the new module. To install the module, use
$ cpan <Module::Name>
$ cpanm <Mоdule::Name>
For the latest (more modern) one, don't forget to install it:
perlbrew install-cpanm
PS. Good luck installing the modules ;-)
You just forgot to run after make test
make install
;-)
Therefore, the module was not found
To install modules, it is better to use the command:
cpan <Module::Name>