chanakya has asked for the wisdom of the Perl Monks concerning the following question:
Monks
I have around 40 modules to load in a script, instead of hardcoding I want to load them dynamically (read the directory and use the modules)
I'm able to get the module names but the script throws an error when i do "use $fmodule"
Please point me to the right direction. Below is the sample script
I have around 40 modules to load in a script, instead of hardcoding I want to load them dynamically (read the directory and use the modules)
I'm able to get the module names but the script throws an error when i do "use $fmodule"
Please point me to the right direction. Below is the sample script
I get the following error when the script is executed#!/usr/bin/perl use strict; use warnings; use File::Basename; BEGIN { my $path = '/path/ABC/*.pm'; my @files = < $path >; foreach my $mod(@files){ my($filename, $directories, $suffix) = fileparse($mod); $filename=~s/\.pm//gx; use $filename; } }
Please let me know the correct way of loading the modules.syntax error at t.pl line 13, near "use $filename" BEGIN not safe after errors--compilation aborted at
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Dynamically load all modules from a directory
by toolic (Bishop) on Oct 01, 2009 at 13:36 UTC | |
by chanakya (Friar) on Oct 02, 2009 at 10:33 UTC | |
by Anonymous Monk on Nov 19, 2014 at 04:34 UTC | |
Re: Dynamically load all modules from a directory
by Fletch (Bishop) on Oct 01, 2009 at 14:34 UTC | |
Re: Dynamically load all modules from a directory
by ELISHEVA (Prior) on Oct 01, 2009 at 15:27 UTC | |
Re: Dynamically load all modules from a directory
by jakobi (Pilgrim) on Oct 01, 2009 at 13:38 UTC |
Back to
Seekers of Perl Wisdom