On 11/08/2014 10:40 AM, Ron Bergin wrote:
Patton, Billy N wrote:
I currently have something like this
use MyFoo::ABCBar;
use MyFoo::DEFBar;
use MyFoo::HIJBar;
my $fooABC = MyFoo::ABCBar->new();
…
What I would like to do is
foreach $pgm ( ‘ABC’ , ‘DEF’ , ‘HIJ’) {
my $foo = MyFoo::{$pgm}Bar->new;
…
}
This gives me an error.
What is the correct syntax?
I don't see any valid reason why you'd want to do that, but if that's what
you want, you could accomplish it with the use of eval.
my $foo = eval "MyFoo::${pgm}Bar->new";
ewww. never use string eval for something as simple as that.
my $foo = "MyFoo::${pgm}Bar"->new() ;
that is just fine there. the class in a class method call is just a
string or a bareword so there is no need for eval.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/