On Tuesday 08 Dec 2009 12:18:10 Jeff Pang wrote:
> Shlomi Fish:
> > On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote:
> >> Shlomi Fish:
> >>> Regarding using string eval "" - you can do the same using
> >>> UNIVERSAL::can, which would be safer in this case:
> >>>
> >>> <<<<
> >>> __PACKAGE__->can("asub")->(@params);
> >>
> >> or define a package and use AUTOLOAD method?
> >
> > How will the AUTOLOAD method help you here?
> 
> sub AUTOLOAD {
>      our $AUTOLOAD;
>      print "I see $AUTOLOAD(@_)\n";
> }
> 
> asub("abc");  # prints: I see main::asub("abc")
> 

And how will this help? The OP wanted to call a method by the name of "asub" 
by having it in a separate method. In the AUTOLOAD function you'll have a 
gigantic dispatch statement again.

>  > And AUTOLOAD is almost always not
>  > a good idea.
> 
> Why?
> 

See Perl Best Practices:

http://oreilly.com/catalog/9780596001735

Namely, AUTOLOAD slows down the method lookup considerably, and can cause many 
subtle bugs in the mis-spelling of methods and other subroutines.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to