yaneurabeya has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'm having an issue with one of my scripts where I try and require other Perl modules via eval 'require' using the -I flag and it fails, whereas it works via another eval 'require' in another script, where the includes directories are more hardcoded into the script.
Code:
Module Validator (simple):try/foo.pm:#====================== #BEGIN MODULE VALIDATOR #====================== #!/usr/intel/bin/perl -dw use vars qw( $TOP_MODULE $DEBUG ); use pm::Common; use package_name::module; $DEBUG=0; $TOP_MODULE="Module Validator"; &error(-1, "Inappropriate arguments specified! One, and only one, modu +le must be defined") if($#ARGV != 0); &error(-2, "Bad module syntax. Only a-z, A-Z, 0-9, '_' are allowed fo +r the name, with :: as package scoping separators") if($ARGV[0] =~ /[ +^\w:\.]/); local $@=0; eval 'require "'.$ARGV[0].'";'; if($@) { &error(1, "Failed include stage for '$ARGV[0]'. Error message:\n$@ +"); } else { # ... } print "$ARGV[0]: Valid\n"; sub error { &Common::error(@_); } #====================== #END MODULE VALIDATOR #======================
Run / output:#===================== #BEGIN FOO::TRY #===================== package foo::try; + + use pm::Common; + + + 1; #===================== #END FOO::TRY #=====================
filc8166[559]% perl -I`pwd` ./bin/Module_Validator.pl foo::try + + Loading DB routines from perl5db.pl version 1.27 Editor support available. + + Enter h or `h h' for help, or `man perldebug' for more help. + + DB<1> s main::((eval 7)[./bin/Module_Validator.pl:16]:1): 1: require "foo::try"; main::(./bin/Module_Validator.pl:7): 7: DB<2> c (Module Validator) ERROR: Failed include stage for 'foo::try'. Error m +essage: Can't locate foo::try in @INC (@INC contains: /nfs/fm/disks/fm_vt_n190 +29/users/gwcooper/vibe_regress /usr/intel/pkgs/perl/5.8.5/lib/5.8.5/i +686-linux-64int /usr/intel/pkgs/perl/5.8.5/lib/5.8.5 /usr/intel/pkgs/ +perl/5.8.5/lib/site_perl/5.8.5/i686-linux-64int /usr/intel/pkgs/perl/ +5.8.5/lib/site_perl/5.8.5 /usr/intel/pkgs/perl/5.8.5/lib/site_perl .) + at (eval 7)[./bin/Module_Validator.pl:16] line 1. + + Backtrace: at ./bin/Module_Validator.pl line 40 main::error(1, 'Failed include stage for \'foo::try\'. Error m +essage:\x{a}Can\'t ...') called at ./bin/Module_Validator.pl line 19 Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<2> q filc8166[560]% pwd /nfs/fm/disks/fm_vt_n19029/users/gwcooper/vibe_regress filc8166[561]% ls foo/ try.pm
Any ideas what could be wrong?
Thanks in advance!
-Garrett
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Issues with including via eval 'require'
by jettero (Monsignor) on Apr 26, 2007 at 17:31 UTC | |
by yaneurabeya (Novice) on Apr 26, 2007 at 18:45 UTC | |
by Anonymous Monk on Apr 27, 2007 at 08:05 UTC |