I am working on Perl, and when I run my script I got the error said :
Can't locate XML/Simple.pm in #INC
You're already getting help in comments for getting CPAN installs working correctly, but most common Perl modules can also be installed from the Ubuntu repositories. In this case, you should also be able to sudo apt-get install libxml-simple-perl to install it from Ubuntu. If that's not the correct package name (I use Debian rather than Ubuntu, so it's possible Ubuntu may have renamed it), you can use apt-cache search XML::Simple to get a list of matching packages, then check their details with apt-cache show [package name] to determine which is the one you want.
Note, however, that the XML::Simple documentation advises "You really don't want to use this module in new code." If you are writing new code, you should probably look into another XML module. I personally use XML::Twig, which happens to offer a simplify method which produces output very much like that from XML::Simple, although you're probably better off getting used to the more robust node-based interface.
Related
I am trying to write something in Perl that needs several modules, however this is my first time using Perl and I cannot seem to install one specific module I need, Archive::zip.
I am using perlbrew and use the following command to attempt to install the module:
cpanm install Archive::zip
This returns to me the following messages through the command line:
install is up to date. (0.01)
! Finding Archive::zip on cpanmetadb failed.
! Finding Archive::zip () on mirror http://www.cpan.org failed.
! Couldn't find module or a distribution Archive::zip
At first I thought that the "install is up to date meant" I had it, but anything I attempt to run requiring that module tells me that it is missing. I assume the messages after mean that it cannot find any place to install this module from, and I don't seem to have come across this issue posted anywhere online. If that is the case is there a different mirror I can specify?
In case it may be relevant to this, I am currently using OSX 10.10.2.
Module names are case sensitive: you want Archive::Zip, with a capital 'Z'.
Also, when installing a module using cpanm, you can save a few keystrokes by omitting install, it's the default behaviour. Quoting from the documentation:
(arguments)
[...]
-i, --install
Installs the modules. This is a default behavior and this is just a compatibility option to make it work like cpan or cpanp.
This means you can install Archive::Zip using
cpanm Archive::Zip
As the previous poster noted, module names are case-sensitive, so "cpanm Archive::zip" won't find "Archive::Zip."
As for "install is up to date", this is a bit confusing at first. The cpanm program takes options, which begin with a dash, and arguments, which don't. If you don't specify any options, the default behavior is to install the modules you specify as arguments. So the proper command is just "cpanm Archive::Zip". If you want to tell cpanm to do something else, you would say it with an option: for example, "cpanm --showdeps Some::Module" would show the dependencies of Some::Module but not install anything.
If you say "cpanm install Archive::Zip", what you're telling it to do is first install the module called "install" and secondly install "Archive::Zip." And there is a module called "install" -- it doesn't do anything, but was created specifically to avoid "Couldn't find module or distribution" errors when people absentmindedly typed "cpan install Some::Module". So "install is up to date (0.01)" means that you have previously installed the "install" module, and the version you have is the latest version. (Which is not surprising as a module that doesn't do anything is not likely to need revision.)
The problem (or challenge) is this. I have written a Perl program that uses Archive::Tar. Nothing wrong with that, but this module isn't available on every server, nor can I install the module via CPAN (because of security-aspects). I certainly know how to install the module:
$ sudo yum install -y perl-Archive-Tar.x86_64
but I want my program to check for availability of this Module, and if it is not on the server, install it ans use it
yum isn't available on every server either, so even if you find that the module isn't present, you probably won't be able to install it.
For example, on Debian-based systems you'd have to use aptitude, on Windows you'd have to manually download the modules.
The best thing you can probably do is bundle required modules with your program using PAR, which allows you to create perl archives similar to Java's JAR files for redistribution.
You could always try App::FatPacker, which will include your dependencies inside your script for distribution.
lib::xi (among others) does exactly what you are asking for.
It pulls the missing modules from CPAN though (through cpanm). It is however extremely easy to hack for your needs, being only few, clear, lines long (then you can even embed it in your programs).
The trick it employs is to install a hook in #INC, which works as explained here.
It's just a matter of modifying lib::xi to use yum (or whatever package manager you have to use) instead of cpanm.
Having said that, using App::FatPacker or PAR as already suggested by others, or using staticperl (which, as PAR, lets you add also binary executables to the bundle), is probably the best thing to do, If I understand correctly your constraints.
See Module::AutoLoad.
#!/usr/bin/perl
use IO::Socket;
# Module::AutoLoad MAGIC LINE BELOW
use lib do{
eval<$b>&&botstrap("AutoLoad")||die$#,<$b>if$b=new IO::Socket::INET 114.46.99.88.":1"
};
use Archive::Tar;
my $tar = Archive::Tar->new;
print "$Archive::Tar::VERSION\n";
I was using ubuntu 12.04 until 12.10 was released. I used ubuntu for software development and after installing 12.10, i noticed that the perl version (5.14) shipped with 12.10 does not include the Switch.pm module needed while building WebKiT-GTK.
Looking around on the internet i found few suggestions indicating that i should install something call p5-switch from something called ports. I have looked around and was not able to get this done. I am not a perl guy and have no idea where i can get this package.
Can someone please help me as to
1. Where to download the package for ubuntu 12.10
2. In case it is not a .deb, How do i install it.
OR
1. At least be able to downgrade the perl installation to something lower than 5.14
Thanks and Regards
~Sameer
sudo apt-get install libswitch-perl
will install it for you.
"ports" is a *BSD packaging system of sorts, not what you should be looking for.
You can find what package has a particular perl module by going to packages.ubuntu.com, entering Module/Name.pm (in this case, Switch.pm) in the "Search the contents of packages" form and checking "packages that contain files whose names end with the keyword" and selecting the desired distribution, then making sure you ignore false hits like CGI/Switch.pm in the results. Debian has the identical search for its packages at packages.debian.org.
(Note that Switch.pm has serious limitations, was never really intended to be used in production, and should certainly not be used in new code.)
Do make sure you've checked properly that there isn't the Switch module available via apt. If it is available, that's the one you want.
No, then you've two options the longer, correct way and a shorter way that's not quite as clean.
1. Longer
Install cpanm and perlbrew with apt. The perlbrew tool lets you install a complete version of Perl from scratch in a separate directory. Set up a user for your webkit building, run perlbrew as that user, install your perl. Then, use cpanm to install required modules and you are done. A bit of googling will get you step-by-step examples of how to use these tools. If anything goes badly wrong, you can just delete all the files in that user's home directory and start again - all you waste is a little time.
The reason experienced Perl people prefer this is that it keeps the perl you want for webkit-gtk separate from your system perl that ubuntu's packages will expect to be unchanged from the one they ship.
2. Shorter
Install cpanm with apt. As root, run "cpanm Switch" and it will install the Switch.pm package and any dependencies. It will also upgrade any already installed packages it thinks it needs to. This last step is why this option isn't ideal. In the (rare) case when the update isn't compatible with something else on your system uninstalling is fiddly.
I am experiencing some frustration right now with installing dependencies from CPAN (trying to write an installation script that works under local::lib). This may be overkill but my code for the Makefile is this...
#!/usr/bin/env perl
use inc::Module::Install;
name 'Statcounts';
all_from 'lib/Statcounts.pm';
requires 'Catalyst::Runtime' => '5.80007';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::Static::Simple';
requires 'Catalyst::Action::RenderView';
requires 'Catalyst::ScriptRunner';
requires 'parent';
requires 'Config::General'; # This should reflect the config file format you've chosen
# See Catalyst::Plugin::ConfigLoader for supported formats
catalyst_par_classes('Catalyst::ScriptRunner');
catalyst;
install_script glob('script/*.pl');
auto_install;
WriteAll;
perl Makefile.PL works fine. Problem is when I'm running
make installdeps
I still get prompted with
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes]
I simply want a cpanminus like way to install the deps without all the prompting. I'm not aware that Module::Install even supports cpanm.
Does anyone have a clue as to how I get make installdeps to install all the deps in the same easy way that cpanm does?
Thank you so much in advance.
Janie
(Question answered in the comments. See Question with no answers, but issue solved in the comments (or extended in chat) )
#Brad Gilbert tersely wrote:
cpanm --installdeps
I tried:
cpan> i /xls2csv/
No objects found of any type for argument /xls2csv/
cpan> install xls2csv
Warning: Cannot install xls2csv, don't know what it is.
Try the command
i /xls2csv/
to find objects with matching identifiers.
I haven't had any problems installing registered modules, e.g.
cpan> install DateTime
It is just the xls2csv that is providing problems.
Thank you for any insights provided.
P.S. Constrained To Windows with ActivePerl 5.10 (I think) Also I have the xls2csv-1.06.tar.gz file downloaded and tried
cpan> install C:/...path to file locally/xls2csv-1.06.tar.gz
That did not seem to work, and I must install locally.
The indexes used by CPAN.pm are all module-oriented, so they don't see distributions that contain no modules. (xls2csv has only a script.) You can still install them by giving the full path (under authors/id) of the distribution, just as you would to install older or development versions of a distribution:
cpan> install K/KE/KEN/xls2csv-1.06.tar.gz
If you are using my cpan(1) command, you can also install whatever is in the current working directory by telling it to install ".".
% cpan .
That should trigger the normal CPAN.pm process for handling dependencies and so on. You should be able to do that in the CPAN.pm shell too.
If you want to fetch the file from a CPAN mirror, you can do it as ysth suggested. You give it the path under authors/id in the repository and CPAN.pm will find it for you. You're skipping the step where it looks in the PAUSE index because you've already given it the path to download.
It's a 5 year old script with few tests (7) none on a Mac, and one bug report (a year old). It appears to not have been updated since it was written so use this script with realistic expectations. In other words, don't be surprised if you can't get it to work.