Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Bad Name or Missing @INC entry - "require" path fail.

by punch_card_don (Curate)
on Feb 26, 2013 at 06:45 UTC ( #1020610=perlquestion: print w/ replies, xml ) Need Help??
punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Morphological Monks,

This is going to turn out to be something maddeningly simple...

I migrated a script from one host to another. Works fine on the old. But on the new I get an error:

Bad name after main' at ../config.pl line 18.
That line of code is a require:
require "../config.pl";
to load up some configuration variables. The file is located up one directory from the script and is chmoded 755.

If I change the relative path to anything else - like ../../ or ./ or just the filename, then I get

Can't locate ../../config.pl in @INC (@INC contains: .....
and a list of the directories in @INC.

Why the one error when the path is ../ and the other for any other path? Do I need to add something to @INC to include the current directory of the script that's running?

Thanks.

*****UPDATE*****

Solved - please see my last post below.




Time flies like an arrow. Fruit flies like a banana.

Comment on Bad Name or Missing @INC entry - "require" path fail.
Select or Download Code
Re: Bad Name or Missing @INC entry - "require" path fail.
by manorhce (Beadle) on Feb 26, 2013 at 07:05 UTC

    you are using relative path, for which you are getting the error, use absolute path the module provide is module File::Spec qw(rel2abs)

Re: Bad Name or Missing @INC entry - "require" path fail.
by Khen1950fx (Canon) on Feb 26, 2013 at 07:20 UTC
    The reason that you want to use an absolute path is that require() will just make an attempt to read the file without checking @INC; however, if you give a relative path, require() will check all the files in @INC, hence the error...
    Can't locate ../../config.pl in @INC
Re: Bad Name or Missing @INC entry - "require" path fail.
by punch_card_don (Curate) on Feb 26, 2013 at 07:30 UTC
    Thanks for the replies so far.

    Reading, I found

    http://perl.apache.org/docs/general/perl_reference/perl_reference.html#use____require____do_____INC_and__INC_Explained

    which points out:

    First, let's see what are the contents of @INC on my system: % perl -e 'print join "\n", @INC' /usr/lib/perl5/site_perl/5.005 . Notice the . (current directory) is the last directory in the list.
    And I note that in the error message I receive, "." is the last entry. That is, @INC does in fact have the current directory in it. So I think that when I use the correct relative path, "../", it is finding it.

    So the mystery is the original "bad name" error.




    Time flies like an arrow. Fruit flies like a banana.
Re: Bad Name or Missing @INC entry - "require" path fail.
by punch_card_don (Curate) on Feb 26, 2013 at 07:42 UTC
    OK - figured it out.

    As mentioned in my post above - the "." current directory was in @INC, so it was doing the relative path from the current directory just fine when the relative path was correct. Of course when I changed it to something incorrect, it correctly reported that it could not find config.pl with that relative path from any of the iclude directories in @INC.

    The error was in the required file, config.pl. Where, on line 17 (not 18 as reported), there was a typo just after "main'".

    "at ../config.pl" in the error message was referring to "in the required file, ../config.pl, at line 18", not "at line 18 of the current script at ../config.pl".




    Time flies like an arrow. Fruit flies like a banana.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1020610]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-10-24 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (131 votes), past polls