Hi shahj,

Instead of "require package_name" you may say use package_name.

As 'require' is not bringing in the symbols. Only 'use' does it.

You should always use 'use' when you wanted to bring in the symbols
inside your script from the package.

More importantly the package 'package_name' should be exporting the
functions or variables that you want to use it in any script.

Perl looks into 'use' statements during compile time, but push() or
unshift() gets executed only at run-time.

So you enclose push() or unshift() inside BEGIN block as it always gets
executed during compile time.

And then use 'use' ....;) I mean don't use 'require'.

A sample code will be
-----------
#!/usr/bin/perl

BEGIN{
my $path = "../";
push(@INC,$path);
}

#require sample; #Don't use require...
use Sample(simple);

simple("Hello World");

-----------

Sample.pm is in ../ directory.

And the contents of it is as follows
----------
package Sample;

BEGIN {
use Exporter ();
our (@ISA, @EXPORT);

@ISA = qw(Exporter);
@EXPORT = qw(&simple);
}

sub simple {
  print "--->@_\n";
}

1;
---------

This is how exporting is done.

This is one way of doing it. Probably there could be some other short
and sweet ways of doing it. I'm also waiting for such an answer.

With Best Regards,
R. Kamal Raj Guptha.


-----Original Message-----
From: PerlDiscuss - Perl Newsgroups and mailing lists
[mailto:[EMAIL PROTECTED]
Sent: Thursday, July 29, 2004 10:45 AM
To: [EMAIL PROTECTED]
Subject: Modifying @INC


I want to add some paths to the @INC array to resolve certain package
names at runtime.

One of the methods is: "push(@INC,$path) or unshift($path,@INC)" and
then
say "require package_name;".
the problem with this is that we still need to use the "::" operator
with
the symbols to resolve the package namespace.
eg: package_name::test_sub();

The other method that I came across was to use the PERL5LIB/ PERLLIB
environment variable. This actually needs us to create an OS level env
variable, which I would like to avoid.

Apart from these is there a method that can modify @INC  at runtime.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>






Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to