in reply to Re: Re: Re: Load all modules in directory
in thread Load all modules in directory

For me, your code results in
Can't locate C:/Perl/site/lib/ACME in @INC (@INC contains: C:/Perl/lib + C:/Perl/site/lib .) at C:\Dokumente und Einstellungen\foo\Desktop\t. +pl line 10. BEGIN failed--compilation aborted at C:\Dokumente und Einstellungen\fo +o\Desktop\t.pl line 12.
I just tried to use eval to trap some nasty error messages and I got away with it -- I highly doubt whether this is legal, though:
#!perl use strict; use warnings; BEGIN { my $dir = "C:/Perl/site/lib/"; my $r; for (<$dir*.pm>) { /([^\/]+)$/ && ($r = $1) or next; eval { rquire $_ } unless ($r and $INC{$r}); } } use Data::Dumper; print Dumper \%INC;

Anyway, I hope this helped the OP.
CombatSquirrel.
Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Load all modules in directory
by hanenkamp (Pilgrim) on Dec 10, 2003 at 20:07 UTC

    The error you point out is part of the reason I suggested changing * to *.pm. Directories won't load very happily. Although, in this case we could add this instead of the *.pm:

    require $_ unless -d $_;

    But, with this solution, we'd still run into problems if there are other odd files like READMEs or something else that got stuck in the directory we are scanning.