<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>Hi 
All,</FONT></SPAN></DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>&nbsp;I'm working on 
a TK app, and I'm struggling with a few things.</FONT></SPAN></DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>I have a function 
which looks a bit like this:</FONT></SPAN></DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>sub 
new_object</FONT></SPAN></DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial 
size=2>{</FONT></SPAN></DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>&nbsp;my 
$object=My::Class-&gt;new();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# 
Create a new object to monitor<BR>&nbsp;my 
$tl=$mw-&gt;Toplevel;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
# Create a top-level 
window.<BR>&nbsp;$tl-&gt;title($object-&gt;{'name'});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
# Set the title of the new 
window.<BR>&nbsp;$tl-&gt;Label(-text=&gt;"Name:")-&gt;grid(-row=&gt;0, 
-column=&gt;0);&nbsp;# Add Labels to 
window.<BR>&nbsp;$tl-&gt;Label(-textvariable=&gt;\$object-&gt;{'name'})-&gt;grid(-row=&gt;0, 
-column=&gt;1);<BR>&nbsp;$tl-&gt;Label(-text=&gt;"IP 
Address")-&gt;grid(-row=&gt;1, 
-column=&gt;0);<BR>&nbsp;$tl-&gt;Label(-textvariable=&gt;\$object-&gt;{'ip'})-&gt;grid(-row=&gt;1, 
-column=&gt;1);<BR>&nbsp;$tl-&gt;Label(-text=&gt;"Uptime:")-&gt;grid(-row=&gt;2, 
-column=&gt;0);<BR>&nbsp;$tl-&gt;Label(-textvariable=&gt;\$object-&gt;{'uptime'})-&gt;grid(-row=&gt;2, 
-column=&gt;1);<BR>&nbsp;$tl-&gt;Button(-text=&gt;"Exit", 
-command=&gt;sub{$tl-&gt;destroy()})-&gt;grid(-row=&gt;20, 
-column=&gt;0);&nbsp;# Create an exit button.<BR>&nbsp;$tl-&gt;repeat(5000, 
sub{$object-&gt;update_status()});&nbsp;# Update the status every 5 
seconds.<BR>}</DIV></FONT></SPAN>
<DIV><SPAN class=791150423-08122008><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>Now this works as it 
is, but I just know it won't scale well. I would rather have a single class 
method I could call which would run update_status() on all objects of it's 
class, and call it from the main window ($mw in this case). So my first question 
is, how can a class access all instances of itself? I considered creating an 
array in which I could store a reference to all objects, but that just seems 
wrong, 'cause it will prevent objects from going out of scope when all other 
references to them are deleted.</DIV></FONT></SPAN>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2>The second question 
is in relation to keeping $object in scope. If I remove the last line of the 
above function, $object goes out of scope as soon as the function completes. 
Having a label with -textvariable=&gt;\$object{'anything'} isn't sufficient to 
keep $object in scope.</FONT></SPAN></DIV>
<DIV><SPAN class=791150423-08122008><FONT face=Arial size=2><SPAN 
class=791150423-08122008>So, if I was to create a class method as required, 
there would be no objects to call update_status() on.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2>However, with the function as it is above, even 
destroying $tl (when the user clicks on the 'Exit' button) doesn't call DESTROY 
on $object. There must be some reference to the object somewhere<SPAN 
class=791150423-08122008>,&nbsp;created by $tl-&gt;repeat(), which isn't going 
out of scope when $tl is destroy()ed.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=791150423-08122008>Anybody care to shed 
some light on this?</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=791150423-08122008></SPAN></FONT>&nbsp;</DIV>
<DIV align=left>
<DIV align=left><FONT face=Arial 
size=2>Regards,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Leigh</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Leigh Sharpe<BR>Network Systems Engineer<BR>Pacific 
Wireless<BR>Ph +61 3 9584 8966<BR>Mob 0408 009 502</FONT></DIV>
<DIV><FONT face=Arial size=2>Helpdesk 1300 300 616<BR>email <A 
title=mailto:lsharpe@pacificwireless.com.au 
href="blocked::mailto:lsharpe@pacificwireless.com.au">lsharpe@pacificwireless.com.au</A><BR>web 
<A title=http://www.pacificwireless.com.au/ 
href="blocked::http://www.pacificwireless.com.au/">www.pacificwireless.com.au</A></FONT></DIV></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>