Put it in a subroutine , call subroutine and give it args, have subruotine return values, subroutines are easy to call repeatedly , programming is all about well named suboutines calling each other .... and zero global variables Main( @ARGV );
exit( 0 );
sub Main {
my $lessons = DatabaseOperations( 'ro', 'sham', 'bo' );
my $myframe = MyFrame->new( $lessons );
...
$simpleapp->MainLoop;
}
## FetchLessons??
sub DatabaseOperations {
my( $ro, $sham, $bo ) = @_;
my $dsn = "dbi:mysql:$ro";
my $dbh = DBI->connect( $dsn, $sham, $bo ) ...
...
return \@lessonsimplename;
}
sub MyFrame::new {
## NO LONGER USING "fake" GLOBAL VARIABLE @lessonsimplename
my( $lessonsimplename ) = @_;
...
my $combobox1 = Wx::ComboBox->new( $panel,
-1,
$lessonsimplename->[0],
[50, 110],
[-1, -1],
$lessonsimplename,
0,
...
The key is to put everything into well named subs :) subroutines that take arguments, not work with "fake" global variables , file scope my globals, lexical globals , global lexicals, fake globals they nullify the helpfulness of strict :) read about it http://perl.plover.com/flagbook/yak/Chi/slide040.html Tutorials: Variable Scoping in Perl: the basics, Coping with Scoping , Mini-Tutorial: Perl's Memory Management, Lexical scoping like a fox, Read this if you want to cut your development time in half!, Closure on Closures , perlref#Circular References, Memory leaks and circular references, Circular references and Garbage collection., make perl release memory, about memory management , Re^3: Scope of lexical variables in the main script , Re: What's the weaken here for?, Devel::Cycle, Devel::NYTProf, Devel::Leak Devel::LeakTrace, WeakRef | [reply] [d/l] |