in reply to Re: using a variable to specify which perl module to use
in thread using a variable to specify which perl module to use
require "Text::CSV" is much different than require Text::CSV. For your code to work, you'd need to s-::-/-g on $module for the require (but not for the import).
You can also use a lexical. Note that my declarations happen when the statement is compiled but my initializations happen when the statement is run. So:
Using eval "use $module" avoids this complication. Which to prefer is mostly a matter of taste (unless there is "risk" of $module ending up containing something strange). - tyeuse strict; my $module; BEGIN { $module= ... ? 'Text::CSV' : 'Text::CSV_XS'; my $file= $module; $file =~ s-::-/-g; require "$file.pm"; $module->import(); } my $csv = $module->new();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: using a variable to specify which perl module to use (bareword)
by William G. Davis (Friar) on Jul 15, 2003 at 18:45 UTC | |
by tye (Sage) on Jul 15, 2003 at 19:14 UTC | |
|
Re: Re^2: using a variable to specify which perl module to use (bareword)
by broquaint (Abbot) on Jul 15, 2003 at 21:51 UTC |