1

I have a couple files that are similar and I want them both to require a third file in which I can keep the commonalities. The third file, however, needs to make use of the variables declared in the first two files. If I understand correctly, I should be able to declare them using our in the first two files to be able to modify them in the third.

However, I don't even get that far. I don't seem to be able to require correctly. It claims it "Can't locate" my relative path, even though it is relative to something in @INC that it lists immediately after. It even gives that error if I use an absolute path, which I'm not keen on anyway.

The file has the same permissions as its neighbours, and I can access it via the web browser (it doesn't print anything, but if I make it die() it dies properly, so I know Apache is able to access it, at least.) Nothing funny in the path: it matches =~ '^[0-9a-z_./]+$'

It's not a compile error because, in trying to debug this, I commented out everything besides the last line, which is the 1; that require() needs to succeed.

What might I be doing wrong?

Update per ikegami's request:

eval { require '../test/testform_common_source.pl' };

or

eval { require '/home/myappdev/test/testform_common_source.pl' };

both produce

Can't locate /home/myappdev/test/testform_common_source.pl in @INC (@INC contains: /home/myappdev/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /etc/httpd) at /home/myappdev/test/testform_step_2.pl line 75.

Update 2 per ikegami's request:

-rw-rw-r--   1 chopper chopper 2090 Oct 28 12:34 testform_common_source.pl
-rw-rw-r--   1 chopper chopper 5608 Oct 29 06:51 testform_step_2.pl
Kev
  • 15,899
  • 15
  • 79
  • 112
  • 1
    Re: "It claims it "Can't locate" my relative path", Please provide the complete error message, the value passed to `require` and the full path to the file being required. Feel free to make substitutions to retain privacy (e.g. change your user id to `userid` or `foo` and your company name to `company` or `bar`, etc). – ikegami Oct 28 '13 at 16:53
  • @ikegami, I'm not sure how it helps if I make substitutions, but anyway, it's posted above. – Kev Oct 29 '13 at 10:44
  • Step 2. What's the output of `ls -l /home/myappdev/test/testform_common_source.pl /home/myappdev/test/testform_step_2.pl` – ikegami Oct 29 '13 at 10:49
  • @ikegami, As I said in the OP, the file has the same permissions as its neighbours and can be accessed by httpd, but I pasted as you requested. What are you actually looking for? – Kev Oct 29 '13 at 11:23
  • There's no reason for Perl to be giving you that error based on what you said. You could double check for non-printable characters that might have gotten lost in the copy and paste. (Note that I noticed that you either didn't run the command I asked or you chopped off some of the output. Not the right way to inspire confidence in your claims.) – ikegami Oct 29 '13 at 11:27
  • @ikegami, unprintable characters in my path? No, all [0-9a-z._/]. And like I said, Perl can read the file all right if I access via web browser (I assume at some level mod_perl is doing an `eval {require...}` on a slurp of my .pl file that way too.) 'K, thanks for checking things, I guess I'm not crazy... – Kev Oct 29 '13 at 11:32
  • Yeah, like a trailing space or newline. Registry? it reads the file then does `eval "sub { $file }"` – ikegami Oct 29 '13 at 13:25
  • All directories in the complete path need to have the x bit, otherwise `testform_common_source.pl` is not accessible, even if it has the r bit. – Slaven Rezic Oct 30 '13 at 10:24
  • @SlavenRezic, they do, I just checked to be sure, but I mean, none of my other scripts would work if they didn't, right? – Kev Oct 30 '13 at 15:13

0 Answers0