in reply to create an object where type is a variable

Your code works as is. The parens are not needed, by the way.
  • Comment on Re: create an object where type is a variable

Replies are listed 'Best First'.
Re^2: create an object where type is a variable
by merlyn (Sage) on Sep 11, 2007 at 15:37 UTC
    "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.
      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.