in reply to Loading and using packages dynamically
my $objName = "foo"; my $testObj = new $objName();
work. Here is the code I used to test.
#!/usr/bin/perl use strict; use warnings; package Foo; sub new { bless {}, shift; } package main; my $objName = "Foo"; my $obj = $objName->new(); my $obj1 = new $objName();
BTW, you can use eval to use modules at runtime and capture problems finding the module, e.g.
my $moduleName = "Foo"; eval "use $moduleName"; if ($@) { # could be problems with the loading of the module Foo .... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Loading and using packages dynamically
by avarus.com.ar (Initiate) on Sep 24, 2007 at 19:53 UTC |