0
votes

Consider the following script "test.pl".

test.pl

#usr/bin/perl -w

push (@INC,"path_for_abc");
use abc;

#rest of the code ...

Command prompt:

$ perl -c test.pl

I know that I will have to add "use lib" pragma or have to push the path inside @INC in Begin block to make it work.

If the path for the module is not defined in defined in @INC, Will "perl -c test.pl" push the "path_for_abc" while snytax checking?

1
It will not, unless, as you mentioned, you use lib or wrap the push into a BEGIN block. - Grrrr
I don't really understand your question. What makes you think that perl -c is different from perl in this regard? - Borodin

1 Answers

0
votes

No, your sample code won't find the "abc" module when run as perl -c. It won't find it when run without -c either but you appear to know that already. use happens at compile time. The push won't happen until runtime unless it's wrapped in a BEGIN block. If you do that (or use lib) then it will work under perl -c. From perlrun:

-c

causes Perl to check the syntax of the program and then exit without executing it. Actually, it will execute and BEGIN, UNITCHECK, or CHECK blocks and any use statements: these are considered as occurring outside the execution of your program. INIT and END blocks, however, will be skipped.