in reply to Re: Module and software path
in thread Module and software path

I like the last option.... especially if other people are going to use my module..When you have this:
use module path => "/usr/local/etc/software";
How exactly is the path being passed to the module? Is the path a scalar variable? Why do you use the => sign?

Replies are listed 'Best First'.
Re: Re: Re: Module and software path
by jasonk (Parson) on Mar 17, 2003 at 19:38 UTC

    If the module is a subclass of Exporter (most are), then when you use it, it's import() method gets called, so in the module you would put:

    package module; use vars qw/@ISA/; @ISA = qw(Exporter); my $path; sub import { my $self = shift; my %args = @_; # of course you would do something more useful than # just printing it print "The path is $args{path}\n"; # at the very least you probably want to store it # somewhere you can get at it later. $path = $args{path}; }

    The arguments after use are passed to import directly as a list, the => sign has the same meaning as a comma, but I like it because it makes it more obvious that the /usr/local/etc/software is related to the path.


    We're not surrounded, we're in a target-rich environment!
      # ./test.pl Bio.pm did not return a true value at ./test.pl line 7. BEGIN failed--compilation aborted at ./test.pl line 7.
      That's the error I am seeing when I plugin your code in my module. In fact, I commented everything out of my module but just your code, so it should print the path, but I am getting this error instead. What is going wrong?

      test.pl is the file calling the module. It contains:

      use Bio path => "/path/to/software";

        You need to have a

        1; # that's a one
        at the end of your Perl module. use will fail without it.