o_chfa has asked for the wisdom of the Perl Monks concerning the following question:

I have a serverlist in a module called serverNames.pm and a script using it. serverNames.pmmodule is homed in ~/lib and the script is homed in ~/bin. So I used following snippet to retieve my data

# !/opt/OV/bin/Perl/bin/perl -w use FindBin; use lib $FindBin::Bin; # path 2 scripts use lib "$FindBin::Bin/../lib"; # path 2 modules use lib serverNames; # contains ARRAY serverList print @serverList; # very simple, I know ;-)

Before runnig I get following:

$ perl -w pfadTest.pl Name "main::serverList" used only once: possible typo at pfadTest.pl line 7

My snippet with strict

# !/opt/OV/bin/Perl/bin/perl -w use strict; use FindBin; use lib $FindBin::Bin; # path 2 scripts use lib "$FindBin::Bin/../lib"; # path 2 modules use lib serverNames; # contains ARRAY serverList print @serverList; # very simple, I know ;-)

produces:

Bareword "serverNames" not allowed while "strict subs" in use at pfadTest.pl line 6. Global symbol "@serverList" requires explicit package name at pfadTest.pl line 8. Execution of pfadTest.pl aborted due to compilation errors.

The module name in ~/lib is serverNames.pm and my OS is HP-UX **** B.11.11 U 9000/800

update: The script is 755 (-rwxr-xr-x). A call with perl -w ~/bin/pfadTest.pl doesn't help either.

Replies are listed 'Best First'.
Re: FindBin doens't work
by moritz (Cardinal) on Sep 02, 2009 at 11:18 UTC

    You probably meant use ServerNames; (without the "lib" in between).

    If you really want add ServerNames to @INC (which is what lib does) you need to quote it: use lib "ServerNames" - but I don't think that's what you want.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: FindBin doens't work
by Sewi (Friar) on Sep 02, 2009 at 12:48 UTC
    print is your friend :-)
    print'ing out debug messages often helps very much, sometimes combined with Data::Dumper:
    use Data::Dumper; print STDERR '@INC: '.Dumper(\@INC)."\n\%INC: ".Dumper(\%INC)."\n";
    I tend to add the use Data::Dumper; in the same line as the debug print when adding short-time prints which get deleted once the problem is solved. This is no good syntax, but saves you from forgetting to remove the use once you don't longer need it.