I have a problem with perl5 with ubuntu.

I've got a script, in which I include several directories. When starting the script, the shell returns

Can't locate XML/Twig.pm in @INC (@INC contains:
at /root/cron/bin/xml-gp-data.pl line 9.
BEGIN failed--compilation aborted at /root/cron/bin/xml-gp-data.pl line 9.

Alright, so that means, perl doesn't find that directory. I've checked the directory and the file. Its path is


The code I use to include that directory and file is

use strict;
use warnings;   
use DBI;
use lib qw(/root/perl5/lib/perl5);
use XML::Twig;
use Data::Dumper;
use lib qw(/root/perl5/lib/perl5/);

I didn't write that script myself, so I can't tell you, why it is included twice :-P

Still I don't understand, why perl can't find XML/Twig.pm. It is exactly where I told perl to look for it. Any ideas why this doesn't work and how I can correct it?


Why are you installing things into directories under the root user's home?

You should install packages instead (libxml-twig-perl in this case), and use the system installed software. You also should generally not run things as root.

This is also off-topic for askUbuntu, as it's a general PERL programming question, and probably best asked on main Stack Overflow or elsewhere, instead.

  • Without knowing what the script is supposed to do, why would you suggest that it might be unsuitable to run it as root? Especially since the full path suggests that it might be a cron script. – andol Jan 11 '13 at 16:10
  • It actually is a cron script. Since I'm quite a noob on such things I don't know if and why I can or cannot run it as root :-P Generally I agree with you that one shouldn't run scripts as root but this configuration was made before I got to manage the server and I suppose that it once made sense to do so (as andol said, maybe because it's a cron script). I guess you might also be right that this is rather a Stack Overflow question. I'll try there, too. But could you or andol explain to me, why cron script mus be used as root? Thank you =) – Johannes Nielsen Jan 11 '13 at 17:03
  • I don't know why the cron script needs to be run as root. If it does, so be it. But either way you don't need to install the PERL library you're using into /root as well, since it's packaged in Ubuntu. Just install the package and your script should work, and you can drop the qw lines to use the /root lib path. – dobey Jan 11 '13 at 17:12
  • Well, using dpkg -s libxml-twig-perlreturned Package: libxml-twig-perl Status: install ok installed so I suppose that means, the package is installed and working, isn't it? Does that mean, just removing the wq lines will get the script to work? I'm rather suspicious concerning that since the same script has been running on a different server before (which is now down due to hardware problems) that was configured almost exactly like this one. I will post this in Stack Overflow, so if @andol could explain to me, why cron scripts have to be run as root, I'd be satisfied for now – Johannes Nielsen Jan 11 '13 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.