jkeenan1 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl use strict; use warnings; use lib ("/Users/jimk/tmp/First/lib"); use First; print "Hello, world\n";
Now suppose I assign that directory to @INC in a BEGIN block, then print out the elements of @INC immediately after the BEGIN block, without use-ing First.pm:
#!/usr/local/bin/perl BEGIN: { unshift @INC, qq{/Users/jimk/tmp/First/lib}; } print "$_\n" for @INC; use strict; use warnings; print "Hello, world\n";
Again, that DWIMs:
/Users/jimk/tmp/First/lib /usr/local/lib/perl5/5.8.8/darwin-2level /usr/local/lib/perl5/5.8.8 ... . Hello, world
But when I attempt to use First, Perl can't find it!
#!/usr/local/bin/perl BEGIN: { unshift @INC, qq{/Users/jimk/tmp/First/lib}; } print "$_\n" for @INC; use strict; use warnings; use First; print "Hello, world\n";
Gives:
Can't locate First.pm in @INC (@INC contains: /usr/local/lib/perl5/5.8 +.8/darwin-2level /usr/local/lib/perl5/5.8.8 ... .) at inc.pl line 8. BEGIN failed--compilation aborted at inc.pl line 8.
What am I failing to understand about @INC?
Thank you very much.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assignment to @INC in BEGIN block gives puzzling results
by Corion (Patriarch) on Dec 23, 2006 at 17:30 UTC | |
by jkeenan1 (Deacon) on Dec 23, 2006 at 17:43 UTC |