Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: Re: Load all modules in directory

by CombatSquirrel (Hermit)
on Dec 10, 2003 at 19:48 UTC ( [id://313834]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313834]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found