On Sunday 15 March 2009 11:37:36 am Ludwig Isaac Lim wrote:
> a) How do I prevent namespace collision like in my case? As I said I
> tried "use warnings, -w flags", but it didn't me any warnings. There has to
> be an easier way than to memorize the names of perl's standard modules :-)
True, 'use warnings;' may warn you about a possible name collision with
another namespace, but not when the names (filenames) of modules are
colliding.
Might be best to see manually if there is already a module by that name:
$ perl -e "print \"\$_\n\" for @INC" | xargs -I{} find {} -maxdepth
1 -iname '_MODULENAME_.pm'
Might want to put that on a script. Someone told me people hate scripts, but
at least it's better than memorizing (the modules, or the command, take your
pick) :-) If perl has a facility like this, I don't know of it yet.
> b) I tried putting a BEGIN{ Exporter::Verbose=1} (sorry if there is a
> typo, my Perl book is at the office). The above BEGIN statement is supposed
> to verbosely list all the modules loaded into your program. I saw "A"
> module loaded, but I didn't see the "B" module loaded (which surprised me
> now, since there is a "B" module that comes along with perl.
Here's the output on mine with $Exporter::Verbose = 1:
1 : Carp::EXPORT_FAIL cached: verbose &verbose
at /usr/lib/perl5/5.8.8/Exporter/Heavy.pm line 171.
2 : Importing into Carp from Carp: carp, confess, croak
at /usr/lib/perl5/5.8.8/Exporter/Heavy.pm line 190.
3 : Importing into main from B: at x2.pl line 7
4 : main::BEGIN() called at /usr/lib/perl5/5.8.8/Carp.pm line 7
5 : eval {...} called at /usr/lib/perl5/5.8.8/Carp.pm line 7
6 : Importing into main from Exporter: at A.pm line 4
7 : main::BEGIN() called at A.pm line 4
8 : eval {...} called at A.pm line 4
9 : require A.pm called at x2.pl line 8
10 : main::BEGIN() called at A.pm line 4
11 : eval {...} called at A.pm line 4
12 : Importing into main from A: a at x2.pl line 8
13 : main::BEGIN() called at A.pm line 8
14 : eval {...} called at A.pm line 8
15 : Undefined subroutine &main::b called at x2.pl line 12.
16 : ludwig
17 : A...
Perl's B was loaded (see line 3) but no aliasing was done because the module
doesn't do default exports, contrast this with line 12 where 'a' was exported
automatically by A.pm.
> c) Is the Perl
> -I <dir> a standard practice for working with use defined modules?
Yup, it's what its there for. Usually though, you include a directory where
all your custom modules are. The PWD is included by default but at the lowest
precedence (which explains why a name change corrects the predicament). But
another technique would be to modify @INC:
$ cat x2.pl
#!/usr/bin/perl
BEGIN {
unshift @INC, pop @INC;
#$Exporter::Verbose = 1
}
use B;
use A;
print "${A::egg}\n";
a();
b();
$ perl x2.pl
ludwig
A...
b!...
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph