develooper Front page | perl.beginners | Postings from September 2009

export symbols across directories

Thread Next
From:
Stanisław T. Findeisen
Date:
September 25, 2009 01:59
Subject:
export symbols across directories
Message ID:
4ABC8686.5070503@gmail.com
I am trying to use symbols from Utils.pm without qualifying them with
package name. I have 2 files:

#############################
# File Utils.pm
#############################
package Utils;

use warnings;
use strict;

use base 'Exporter';
our @EXPORT_OK = ('foo', 'bar');

sub foo {
    print "foo!\n";
}
sub bar {
    print "bar!\n";
}

#############################
# The program (1)
#############################
use warnings;
use strict;
use Utils qw(bar foo);

foo();
bar();

If both files are in the same directory, this works fine:

$perl ./prog1.pl
foo!
bar!

When I, however, move Utils.pm into subdirectory mylib, and modify the
program accordingly:

#############################
# The program (2)
#############################
use warnings;
use strict;
use mylib::Utils qw(bar foo);

Utils::foo();
bar();

then only the first call works:

$perl prog1.pl
foo!
Undefined subroutine &main::bar called at prog1.pl line 6.

What is the problem?

Thanks!

STF

=======================================================================
http://eisenbits.homelinux.net/~stf/
OpenPGP: DFD9 0146 3794 9CF6 17EA  D63F DBF5 8AA8 3B31 FE8A
=======================================================================

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About