>     ${$pkg.'::'.$var} = $val;
>     ${"$pkg\::$var}   = $val;
> 
> Still ugly, but not quite as bad as what you came up with.

Thanks - once I saw the first one my brain went "Oh, yeah...."
 
> Ooop, didn't even notice and didn't see the discussion.  Let me see if
> I missed anything... I didn't discuss class methods as opposed to
> object methods.  Will ponder.

It's really dicey. I think it's probably bad, because there's no way to
tell here:

   print "Your name is Class->name";

Whether Class is 'Class' or Class(). The phrase "avoid at all costs"
comes to mind. ;-)
 
> Its a common newbie mistake to do something like this:
> 
>     $var1 = "this";
>     $var2 = "that";
>     $var3 = "wibble";
> 
>     foreach $num (1..3) {
>         print ${"var".$num};
>     }

You're right. A more experienced Perl hacker would have correctly
written that as:

    $var1 = "this";
    $var2 = "that";
    $var3 = "wibble";

    foreach $num (1..3) {
        print ${"var$num"};    # implicit .
    }


(Kidding, point taken) ;-)
 
> Ambiguous.  Consider the following:
> 
>     $class = "Class::Special";
>     $file  = "lib/foo/bar.pl";
> 
>     require $class;  # want:  load "Class/Special.pm" from @INC
>     require $file;   # want:  load "lib/foo/bar.pl" from @INC

!@()*&!@@!$(*&!_)(@*_!

I knew I forgot something.

Ah, well, a man can dream...

> C<eval "require $class"> isn't that hard, but I wouldn't mind seeing a
> more obvious way.

Nothin' leaps out. My brain hurst.
 
> This combines the problems of symbolic references PLUS busting
> encapsulation.  Shouldn't be easy.

I'd just settle for easiER than this:

   &{"${mypkg}::do_stuff"}(@a)  # &{$mypkg.'::'."do_stuff"}(@_) too

It only busts encapsulation if you're using it as an object. If you just
want to get to a function without importing it, then you've gotta type
lots.

But I agree this should remain at least somewhat dicey.

I'm feelin' an RFC retraction comin' on...

-Nate

Reply via email to