freelanceprogrammers.org Forum Index » Perl

Including/Using files...


View user's profile Post To page top
smhinchy Posted: Fri Jan 06, 2006 12:15 am


Joined: 06 Jan 2006

Posts: 3
Including/Using files...
Hello all,

I have some cgi scripts in my /cgi-bin directory on my server. I want
to have some utility-type scripts or packages in the same directory
for consolidation and ease of use. The problem is that when I use the
use directive, such as:

use "utility.pm";

I get an error that the file is not in the search path. I have even
tried prefacing it with "./" and it still does not work.

I guess I am lucky because I actually did get something to work, the
following:

BEGIN {$Defines::module_root = `./`;}
use lib "$Defines::module_root";
use utility;

Then in utility.pm I have to declare "package utility;"

Is there a better/easier/clearer way to do this? I am guessing that
all I did above was to add the current directory to the search path.

Thanks!

Shawn
Reply with quote
Send private message
View user's profile Post To page top
merlynstoneh... Posted: Fri Jan 06, 2006 5:10 am


Joined: 21 May 2004

Posts: 44
Including/Using files...
>>>>> "smhinchy" == smhinchy <shawn@...> writes:

smhinchy> I have some cgi scripts in my /cgi-bin directory on my server.

I would almost certainly bet that you do *not* have files in /cgi-bin,
next to /tmp and /var and /usr and /etc. You probably have them in a
directory that is accessed via a URL that looks like /cgi-bin. And
that`s quite a different thing.

smhinchy> I want
smhinchy> to have some utility-type scripts or packages in the same directory
smhinchy> for consolidation and ease of use. The problem is that when I use the
smhinchy> use directive, such as:

smhinchy> use "utility.pm";

smhinchy> I get an error that the file is not in the search path. I have even
smhinchy> tried prefacing it with "./" and it still does not work.

First, that`s a syntax error. Did you mean "require" instead of "use"?

And, even so, unless it`s somewhere in @INC, your "use" will not work.
What directories are in your @INC?

Also, package names (and therefore module names) that begin with a
lowercase letter are reserved for "pragma" that modify how Perl works:
not end-user code.

smhinchy> I guess I am lucky because I actually did get something to work, the
smhinchy> following:

smhinchy> BEGIN {$Defines::module_root = `./`;}
smhinchy> use lib "$Defines::module_root";
smhinchy> use utility;

smhinchy> Then in utility.pm I have to declare "package utility;"

Yes, "use lib" alters @INC. Other things alter @INC as well. (Again,
please fix the capitalization.)

smhinchy> Is there a better/easier/clearer way to do this? I am guessing that
smhinchy> all I did above was to add the current directory to the search path.

Unless you`re running as root, the current directory is already in the
search path, so something else is going on that you`re not reporting.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Reply with quote
Send private message
View user's profile Post To page top
smhinchy Posted: Fri Jan 06, 2006 10:25 am


Joined: 06 Jan 2006

Posts: 3
Including/Using files...
--- In Perl_Official@yahoogroups.com, merlyn@s... wrote:
>
> >>>>> "smhinchy" == smhinchy <shawn@h...> writes:
>
> smhinchy> I have some cgi scripts in my /cgi-bin directory on my server.
>
> I would almost certainly bet that you do *not* have files in /cgi-bin,
> next to /tmp and /var and /usr and /etc. You probably have them in a
> directory that is accessed via a URL that looks like /cgi-bin. And
> that`s quite a different thing.
>

Actually it is /cgi-bin, right after /bin and before /conf. My http
files are in /httpdocs.

> smhinchy> I want
> smhinchy> to have some utility-type scripts or packages in the same
directory
> smhinchy> for consolidation and ease of use. The problem is that
when I use the
> smhinchy> use directive, such as:
>
> smhinchy> use "utility.pm";
>
> smhinchy> I get an error that the file is not in the search path. I
have even
> smhinchy> tried prefacing it with "./" and it still does not work.
>
> First, that`s a syntax error. Did you mean "require" instead of "use"?
>

I tried require and I get a 500 error.

> And, even so, unless it`s somewhere in @INC, your "use" will not work.
> What directories are in your @INC?
>

Can`t locate news.pm in @INC (@INC contains:
/usr/lib/perl5/5.8.3/i386-linux-thread-multi /usr/lib/perl5/5.8.3
/usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2
/usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2
/usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0
/usr/lib/perl5/vendor_perl) at site.cgi line 9.
BEGIN failed--compilation aborted at site.cgi line 9.

> Also, package names (and therefore module names) that begin with a
> lowercase letter are reserved for "pragma" that modify how Perl works:
> not end-user code.
>

Thanks, I wasn`t aware of this. Fixed.

> smhinchy> I guess I am lucky because I actually did get something to
work, the
> smhinchy> following:
>
> smhinchy> BEGIN {$Defines::module_root = `./`;}
> smhinchy> use lib "$Defines::module_root";
> smhinchy> use utility;
>
> smhinchy> Then in utility.pm I have to declare "package utility;"
>
> Yes, "use lib" alters @INC. Other things alter @INC as well. (Again,
> please fix the capitalization.)
>
> smhinchy> Is there a better/easier/clearer way to do this? I am
guessing that
> smhinchy> all I did above was to add the current directory to the
search path.
>
> Unless you`re running as root, the current directory is already in the
> search path, so something else is going on that you`re not reporting.
>

Any suggestions? I would have expected my current directory to be in
the path, but it doesn`t appear to be. I stole the `use lib` idea
from another perl script that I had in my /cgi-bin directory.

Thanks,

Shawn
Reply with quote
Send private message
View user's profile Post To page top
smhinchy Posted: Fri Jan 06, 2006 10:29 am


Joined: 06 Jan 2006

Posts: 3
Including/Using files...
You helped me track it down, and it was an error on my part. I don`t
know why, but I used the extension .pm instead of .pl.

require "./news.pl";

Works just fine. Thanks!

Shawn
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help