Welcome to the Monastery | |
PerlMonks |
Re: returning values from Perl-Tk eventsby {NULE} (Hermit) |
on Mar 26, 2002 at 23:16 UTC ( [id://154532]=note: print w/replies, xml ) | Need Help?? |
Hi thunders,
Your issues aren't so much related to passing that array around. Your main problem here is that you are trying to use functional code in an event driven framework. The @image_files array is already paired down to one element before any widgets are drawn because Tk doesn't render anything until you call MainLoop. This means your code for pairing down the images has to happen somewhere else, like in your return array function. But before you go re-engineering your code to meet that requirement let me talk about returning your array. Don't do it! You are already passing a reference to the array so when your subroutine returns it has alread been modified. You'll see in my sample code that I don't return *anything* because I don't have to. I also clearly labled my reference, which IMO is a good coding practice. My guess is that you haven't worked that much with event driven programming. I hadn't myself until I started playing a lot with Tk. I think you are on the right track, but there are probably easier (though more long winded) ways to approach what this accomplishes. I think this technique you are using is a neat hack. In either case I hope this helps you. {NULE} -- http://www.nule.org
In Section
Seekers of Perl Wisdom
|
|