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


In reply to Re^3: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl) by Anonymous Monk
in thread Passing arguments to event handlers in WxPerl by pwn01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.