Here is one way to get what you want:

#!/usr/local/perl
use warnings;
use strict;

use mymodule qw(-d -f=MyFileName.dat myfunc);

print "Hellon";
myfunc();
#----end main file----#
#----start mymodule file----#
package mymodule;
use strict;
use Exporter;

our @ISA = qw(Exporter);
our @EXPORT = ();
our @EXPORT_OK = qw(myfunc);

sub import {
   foreach my $arg (@_) {
     if( $arg eq "-d" ) {
        print "Debugging\n"; # or do whatever
     }
     elsif( $arg =~ /-f=(.*)/ ) {
        print "Filename is $1\n"; # or do whatever
     }
   }
   mymodule->export_to_level(1, grep { $_ !~ /^-/} @_ );
}

sub myfunc {
   print "myfunc\n";
}

#----end module mymodule----#

This should work as expected.  use mymodule calls a method named import
which normally calls Exporter::import.  To get arguments (beginning with a
dash) you should override import and parse the arguments yourself.  Then,
once all the arguments have been parsed and collected, the actual import
needs to be done.  To do this, you call the Exporter::export_to_level
function.  However, since you inherited that with the @ISA, then you call it
as mymodule->export_to_level.  This will export the functions remaining in
the @_ array to the package that called this one (because of the 1 in the
argument list -- it is for previous call stack level).  Finally, you need to
remove the arguments from the @_ array so that it only sees functions.  The
grep does that (it removes anything that starts with a dash.

If you have any other questions about this, let me know.

Thanks!
Tanton Gibbs
-----Original Message-----
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: 8/16/2001 3:52 PM
Subject: RE: Re: arguments with a module

what I mean by argument is a switch/option that I pass to the module
that I call whithin my main perl script. Yes I have those line in my
module:
>use vars qw( @EXPORT, @ISA );
>@EXPORT = qw( function_name );
>@ISA = qw( Exporter );
>require Exporter
the module is so long that is not worth posting over here. All I need is
to be able to pass an argument/switch  to it, in my case is a file name.
so I need to have something like
use mymodule -myargument=<value>

I hope I am a little clearer this time.

Thanks

I.S



Troy Denkinger <[EMAIL PROTECTED]> wrote:

>On Thursday 16 August 2001 16:16, F.H wrote:
>> Hi there,
>> Can you use in a perl script a module with an argument. something
like
>> use mymodule -myargument;
>>
>> I get this message: "-myargument" is not exported bt the mymodule
module.
>> I tried in the module this
>> @mymodule::EXPORT = qw(myargument )
>> and still it didn't work.
>
>Is this a module you're creating?  If so, can you post all (if it's
brief) or 
>some of it so we can see what you're trying to do?
>
>I think what you probably want is:
>
>use vars qw( @EXPORT, @ISA );
>@EXPORT = qw( function_name );
>@ISA = qw( Exporter );
>require Exporter;
>
>I'm not sure what you mean by "argument".
>
>Regards,
>
>Troy
>
>


__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas.
Experience the convenience of buying online with Shop@Netscape!
http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at
http://webmail.netscape.com/


-- 
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