in reply to Re: $var as accessor name?
in thread $var as accessor name?

Thank you, everybody, for pointing out my blind spot.

I guess when you're wondering if Perl can do something, you should try it first, because usualy it does :-)

Special thanks to broquaint for this lovely code.

Replies are listed 'Best First'.
Re: Re: Re: $var as accessor name?
by ysth (Canon) on Mar 12, 2004 at 04:46 UTC
    If the method name is a variable, it does have to be a simple scalar (e.g. $obj->$hash{method_foo} won't work).

      That's not strictly true, though it is messy.

      { package test; sub new{ return bless [], $_[0]; } sub meth1{ print 'meth1'; } }; $t=test->new; $t->meth1; meth1 $h{x}='meth1'; $t->${ \$h{x} }; meth1

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
        Shhh...the newbies are listening.

        More seriously, I very occasionally do that to interpolate an expression in a qq string where that makes the code clearer, but even if I did a lot more OO than I do, I don't think I'd ever do it for method names. It's so much clearer to use a temporary scalar. But I guess it depends on what you are used to seeing.