Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl)

by Anonymous Monk
on Sep 20, 2014 at 07:10 UTC ( [id://1101343]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl)
in thread Passing arguments to event handlers in WxPerl

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

  • Comment on Re^3: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1101343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found