frisco
January 23rd, 2004, 13:58
I have a perl script with the following in the top:

[code:1:093a135c60]
#!/usr/bin/perl -w

use strict;
use DBI;
use Unix::Syslog qw(:subs);
use Sys::Hostname;

push @INC, '/home/frisco/bin';
use local::sqlpass;
[/code:1:093a135c60]

Note the last two lines.

If i run this script from the command line, it works fine. If i run it via:
[code:1:093a135c60]
/bin/sh -c /home/frisco/bin/xmms-di
[/code:1:093a135c60]

Then i get this error:
[code:1:093a135c60]
Can't locate local/sqlpass.pm in @INC (@INC contains: /usr/libdata/perl5/i386-openbsd/5.6.1 /usr/local/libdata/perl5/i386-openbsd/5.6.1 /usr/libdata/perl5 /usr/local/libdata/perl5 /usr/local/libdata/perl5/site_perl/i386-openbsd /usr/libdata/perl5/site_perl/i386-openbsd /usr/local/libdata/perl5/site_perl /usr/libdata/perl5/site_perl /usr/local/lib/perl5/site_perl .) at /home/frisco/bin/xmms-di line 9.
BEGIN failed--compilation aborted at /home/frisco/bin/xmms-di line 9.
[/code:1:093a135c60]

I want to run this script via an xmms plugin which calls external programs by using '/bin/sh -c' but can't figure out what the difference is between the two methods. The problem must lie in not calling perl from an interactive shell, but i'm not sure why. Any ideas?

frisco
January 23rd, 2004, 16:33
The problem is something to do with the way perl is preprocessed. If i run 'perl' from the command line and try the two relevant lines, i get the same error:
[code:1:c2df48e87c]
$ perl
push @INC, '/home/frisco/bin';
use local::sqlpass;
Can't locate local/sqlpass.pm in @INC
[/code:1:c2df48e87c]

My solution is to use the '-I' flag:
[code:1:c2df48e87c]
$ perl -I/home/frisco/bin
use local::sqlpass;
print 'it works!';
it works!
[/code:1:c2df48e87c]

Adding that to the first line of the script (#!/usr/bin/perl -w -I/homefrisco/bin) makes my script run correctly.