On Wed, Apr 15, 2009 at 03:24, Patrick Kirsch <pkir...@bookandsmile.de> wrote:
snip
> In one file:
>
> package Util;
> use base 'Exporter';
> our @EXPORT = ('foo', 'bar');
>
> sub foo {
>    print "foo!";
> }
>
> package Amy;
> use Util;  # imports symbols in @EXPORT
> foo();
>
> On execution it gives the error:
>  Can't locate Util.pm in @INC ...
snip

The use statement is roughly[1] equivalent to saying

BEGIN {
    require "modulename";
    modulename->import(@_);
}

The part that is tripping you up is the require.  Require
searches the paths in @INC for a file named modulename.pm.
Failing to find that file it exits with an error.  The
require functions job is to load the file, since the code
you want is already part of the file the require is not
necessary.  This means you can replace your normal use
statement with

BEGIN {
    modulename->import(any args you would have passed to use);
}

1. if you say

use packagename ();

it is equivalent to

BEGIN {
    require 'packagename';
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to