in reply to Re: create an object where type is a variable
in thread create an object where type is a variable

"Works", presuming for any value of $x, the corresponding class understands an empty new call to mean "return a reasonable object of type $x". Have to say this since there's absolutely nothing special about calling new: it's just a method call.

Replies are listed 'Best First'.
Re^3: create an object where type is a variable
by true_atlantis (Acolyte) on Sep 11, 2007 at 15:44 UTC
    Ahh... my problem was that i was trying to do something like this:
    use test::object; my $x='object'; my $y=test::$x->new();

    That didnt work, and i just realized it was because you have to concat the 'test::' and $x... just in case anyone is running into the same issue, it would look like this:
    use test::object; my $x='object'; my $y=test::.$x->new();

    Thank you everyone.
      my $y=test::.$x->new();
      No, that's *definitely* not what you want. More like:
      my $y = "test::$x"->new;
      Oh, and don't use lowercase class names. Uppercase please.