Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!unmvax!uokmax!d.cs.okstate.edu!drd!mark From: mark@DRD.Com (Mark Lawrence) Newsgroups: comp.lang.perl Subject: Proper Use of Packages and Debugging With Same Summary: do 'foo.pl'; do foo'bar($bar, $gex, $snark); Keywords: packages debugging Message-ID: <1990Jul12.143602.23401@DRD.Com> Date: 12 Jul 90 14:36:02 GMT Reply-To: mark@drd.Com (Mark Lawrence) Organization: DRD Corporation, Tulsa, OK Lines: 54 The subject line says it all -- I want to use packages in the way they were intended and I'd like to be able to use the debugger in a script that uses packages. I admit that my concept of how packages were intended to be used may be bogus. The man page says they give a local namespace to the enclosing block so as not to conflict with namespaces of callers (hence, safe re-useability). As an added bonus, they can be put into separate files that other scripts can 'do' (to get the code interpreted in) so that common subs can be made generally available. So, I write myself a few packages to perform operations common to a number of scripts: foo.pl, bar.pl and gex.pl foo.pl: bar.pl: gex.pl: package foo; package bar; package gex; sub foo'DoThis { sub bar'Snicker{ sub main'gex{ ... ... ... } } } sub bar'Snort{ ... } In an example script, towards the top, I say: do 'gex.pl'; do 'bar.pl'; do 'foo.pl'; and then when I want to call one of the functions, I say: do main'gex(args); do bar'Snort(args); # and so forth (The `main' qualifier in gex.pl, BTW, is there on purpose: we actually have a package that does this, because of the example with package dumpvar in the Packages section of the man page. Why use a package if you're not going to take advantage of the alternative namespace? Or am I really confused?) When I fire the script up in the debug mode, I say: c ## where the line number is past the do 'file' type of calls and past one of the lines in which we actually call a sub defined in a function and I get: Undefined subroutine "Snort" called at Script.pl line ## ... I guess it makes sense to me that Snort is an undefined symbol in the `main' namespace, but shouldn't the debugger handle that (especially since in code I qualify it properly?) How do I debug this so that I can 'step' into packages and watch them execute? Now, I just read the package into my file, comment out the package lines and remove the qualifiers and then test the script as if all subs were 'local', as it were. Isn't there a better way? -- mark@DRD.Com uunet!apctrc!drd!mark$B!J%^!<%/!!!&%m!<%l%s%9!K(B "...do justice, love mercy, and walk humbly..." Micah 6:8