> Wiggins d Anconia wrote: > >> > >>my %masks; > >>my %use; > >>my @pkglist; > >>my %pkgdeps; > > > > Why are these declared with a global scope? If they must be then > > something is wrong with your subs. Move these to after your sub > > listing, if your program still works then they are fine as globals, > > otherwise you have broken encapsulation and that leads to more complex > > code. It also means you are not letting 'strict' help you in the manner > > it was designed to. > > Nope, I need %masks, %use, and %pkgdeps to be global because multiple > subroutines will need access to them. >
And that is the exact reason not to do it. The code is becoming spaghetti code because of this very reason, and generally indicates a design issue. Step back and take a look at your data, then come up with the routines (aka this is where OOP comes in). If you allow your subs to break encapsulation like this then tracking down the kind of bug you mention gets progressively more difficult, and becomes a maintenance nightmare in the future, as well as a testing nightmare. It also may mean you will get less help from the list ;-), which is why we stress 'strict' so much, otherwise it becomes a risk to soak up our time as well as your own. > > [snip subs] > > > >>init(); > >> > >>my $original = build_deptree($ARGV[0]); > >>use Data::Dumper; > >>print Dumper(%pkgdeps); > > > > Based on this snippet you should have need for only one global, > > $original. Everything else should be lexical non-file scoped. Remember > > that subs should take values and return values, your init() does neither > > which means its contents can be moved into main, or into build_deptree, > > or you need to be passing it something. > > This program is far from complete. There will be many more functions that will > need access to those global variables. I put those configuration subroutine > calls into init() because it cleans up the main code a bit. > See above, I know that, but that doesn't mean it is the best way :-). > > Try moving all of your subs into a library and keeping your main > > separate, use 'strict' in both files, make every variable 'my'd, when > > that works I suspect your problems will be solved. > This still holds. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>