On Mon, Jun 28, 1999 at 03:48:18PM -0400, Bill Jones wrote: > >From: Ronald J Kimball <rjk@linguist.dartmouth.edu> > > >> |sub AUTOLOAD { > >> | print "Sorry, I don't see a subroutine called '$AUTOLOAD'\n"; > >> |} > >> > >> And hope that __DATA__ doesn't contain the name of some unrelated sub > >> in main... > >> > > > > That concern is valid for the general exercise, not just this specific > > solution. But under this exercise, there are no 'unrelated' subs. The > > idea is simply to call the specified sub if it exists, and print an > > appropriate message if it doesn't. > > (I am definitely a baby perl're :) > > But would not using AUTOLOAD, which I had overlooked in my earlier post, > allow one to look at other name spaces and call those subroutines if they > exist? > The same is true of your original code. Actually, the difference between the original code, using defined(), and this code, using &AUTOLOAD, is not in how they handle other package's subroutines that do exist, but how they handle other package's subroutines that don't exist. With the original code, if you ask for Foo::Bar, and Foo::Bar does not exist, then the code prints the "Sorry, I don't see a Subroutine Foo::Bar" message. But with the AUTOLOAD() code, in the same situation, then you get the fatal error "Undefined subroutine &Bar::Foo called", because there is no &Foo::AUTOLOAD. (Or, if there is a &Foo::AUTOLOAD, then that will be called instead of our &::AUTOLOAD.) Ronald ==== Want to unsubscribe from Fun With Perl? ==== Well, if you insist... Send mail with body "unsubscribe" to ==== fwp-request@technofile.org