in reply to Loading all files in a dir with use via for loop
From the Perldoc for the function use:
Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to((emphasis mine))except that Module must be a bareword.BEGIN { require Module; import Module LIST; }
So you see, the 'use' takes only a bareword: you can't use a variable.
The second doesn't actually execute anything, so the modules named in $plugin are never loaded.
What you want is to eval the use statements:
for $plugin (<Main/*.pm>) { $plugin =~ s!/!::!g; $plugin =~ s/\.pm$//; $plugin = "use $plugin\;"; ## $plugin; eval $plugin; }
As written, that may be risky -- read the documentation on eval (linked above) and understand the risk before implementing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Loading all files in a dir with use via for loop
by Delusional (Beadle) on Sep 29, 2005 at 07:35 UTC | |
by radiantmatrix (Parson) on Sep 29, 2005 at 12:42 UTC | |
by Delusional (Beadle) on Sep 29, 2005 at 13:27 UTC | |
by Delusional (Beadle) on Sep 29, 2005 at 14:09 UTC | |
by radiantmatrix (Parson) on Sep 29, 2005 at 19:57 UTC | |
|