From: Timothy Kohl <[EMAIL PROTECTED]>
Date: Wed, 6 Aug 2003 17:18:07 -0400 (EDT)
Hi,
I am trying to set up an associative array where the values are
method calls (specifically widget creation calls) for Tk.
Ex: (I know this doesn't work)
%Valid=(
"hostname" =>
Entry("width"=>30,"background"=>'darkgreen',-textvariable=>\$curval{"hostname"})
)
The problem is that I am not sure how to quote the value associated
to "hostname" so that later in the program I can do this:
$prop{"hostname"}=$rightframe->$Valid{"hostname"}->pack("side"=>'right');
where $rightframe is a Frame object. and insert the corresponding
method between the arrows to realize the Entry box.
Thanks,
-Tim K.
(longtime lurker, first time [I think] poster)
I'm not sure if I understand quite what you mean, but does
my %Valid
= ("hostname" => sub {
shift()->Entry(width => 30,
background => 'darkgreen',
-textvariable => \$curval{"hostname"});
});
and
$prop{"hostname"}
= &{$Valid{"hostname"}}($rightframe)->pack("side"=>'right');
do what you want? If so, then maybe it's worth figuring out how to make
the syntax less ugly . . .
Or maybe you want "hostname" to map to a class name, that in turn
implements a standard method call in this particular way. That would
improve the calling syntax, with the added bonus of allowing inheritance
to work for you.
Be aware that this technique of stuffing random subs into data
structures is quite powerful, but has some severe drawbacks in perl5,
most notably that values referenced from "sub { ... sub { ... } }" are
never freed. At least in this case, the sub is at top level, and has no
sub-subs (sorry), so that particular problem is not an issue.
-- Bob Rogers
http://rgrjr.dyndns.org/
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm