Actually, i think the 'use MyPackage' statement is what Edwin is trying
avoid, hence the term "magic" ... ?

It's not really a good idea to do this, but you could create a second perl
command in another location (or rename it in the same location ...) which
says:

        /old/perl -MMyPackage $*

Then, whenever you call this new script, it would call the regular perl
command with the added bonus of your wonderful package.

Like i said, though, i wouldn't recommend this for scripting, since the use
command is about as easy and you might screw other things up.  It might be
nice for command-line execution, though ...

-----Original Message-----
From: Tu, Hanming [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 07, 2001 10:39 AM
To: 'Edwin Günthner'; [EMAIL PROTECTED]
Subject: RE: magic import of extensions?


Yes. Here is how

1) In your MyPackage.pm, you import the Exporter module as

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(init doThis doThat);

2) install MyPackage in a search directory, i.e., including your path in
@INC

3) Then in your scr.pl or other programmer's scripts

use MyPackage;

Those subs will be imported into the scripts.

Hanming


-----Original Message-----
From: Edwin Günthner [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 07, 2001 10:30 AM
To: [EMAIL PROTECTED]
Subject: magic import of extensions?


Hi there,

I am wondering if it is possible to create my own module
and to allow programers to use it without any importing or so.

For example, if MyPackage has subs like "init", "doThis", 
"doThat" - is it possible to have a script that looks like:

scr.pl:

init;
doThis $someArg;
doThat $anotherArg $oneMore;

and just run it with 

> perl scr.pl

.. so what I am looking for is a mechanism
to automatically load MyPackage whenever
Perl starts. Is that possible?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to