Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!mhres!jv From: jv@mh.nl (Johan Vromans) Newsgroups: comp.lang.perl Subject: Re: problems with the defined() function Message-ID: Date: 24 Dec 89 20:09:36 GMT References: <1989Dec22.212004.18316@haven.umd.edu> Sender: jv@mhres.mh.nl Organization: Multihouse Gouda, the Netherlands Lines: 33 In-reply-to: louie@sayshell.umd.edu's message of 22 Dec 89 21:20:04 GMT RIn article <1989Dec22.212004.18316@haven.umd.edu> louie@sayshell.umd.edu (Louis A. Mamakos) writes: Louis> What I'm trying to do is call a subroutine whose name is in a Louis> variable. Before doing such a thing, I'd like to use defined() Louis> to tell me if the subroutine exists or not. Louis> ... Louis> Which means that I can invoke the subroutine in 4 different Louis> way, which I expected, but I can't determine if the name of the Louis> suboutine exists or not. That's right. There is no way to determine if a subroutine has been defined. Calling a undefined subroutine is always treated as a fatal error. The best way to obtain what you want is to use 'eval' to call the subroutine, and inspect $@ afterwards, e.g. $subname = "foobar"; $result = eval ("&$subname()"); if ( $@ ) { # failed ... print $@; } else { # suceeded ... } Happy hacking, Johan -- Johan Vromans jv@mh.nl via internet backbones Multihouse Automatisering bv uucp: ..!{uunet,hp4nl}!mh.nl!jv Doesburgweg 7, 2803 PL Gouda, The Netherlands phone/fax: +31 1820 62944/62500 ------------------------ "Arms are made for hugging" -------------------------