Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Tcl::Tk - Tie Hash to Tcl Array and assign hash

by Ardemus (Beadle)
on Jan 20, 2005 at 04:29 UTC ( #423594=perlquestion: print w/ replies, xml ) Need Help??
Ardemus has asked for the wisdom of the Perl Monks concerning the following question:

I'm creating an application using the perl module Tcl::Tk (thanks to Courage for his help). I've used the provided class to tie a perl hash to a tcl array:
tie %curRecord, 'Tcl::Var', $tcl, "curRecord";
I get an error when I assign a hash to the tied hash:
%curRecord = %{SelectedRecords()}; Error: Tix Error: Can't locate object method "CLEAR" via package T +cl::Var" at...
I am using Tix Widgets, but the error is directly related to the line listed above. If I remove the line the error goes away. This code works (and I'm using it in the mean time):
$temp = SelectedRecords(); foreach (keys %{$temp}){ $curRecord{$_} = $temp->{$_}; }
Clearly this isn't a big issue, but I'm curious if anyone knows what's going on. Thanks, Ardemus

Comment on Tcl::Tk - Tie Hash to Tcl Array and assign hash
Select or Download Code
Re: Tcl::Tk - Tie Hash to Tcl Array and assign hash
by Courage (Parson) on Jan 20, 2005 at 21:15 UTC
    Usually you do not go to such a low level of programming when using Tcl::Tk.

    Normally, you use perlTk syntax, while using *all* features of all requested package (Tix, or any other)

    On the other side, looks like tie-ing hashes does not currently fully implemented. Probably because it is rarely needed to do such kind of mapping.

    I assume this lacking method you found will be fixed within next version of Tcl module, meanwhile you can enter to Tcl::Var package (within Tcl.pm):

    sub CLEAR { my $obj = shift; die "STORE Usage: objdata @{$obj} $#{$obj}, not 2 or 3 (@_)" unless @{$obj} == 2 || @{$obj} == 3; my ($interp, $varname, $flags) = @$obj; $interp->Eval("array set $varname {}"); }
    But you'll probably need more hash methods afterwards (FIRSTKEY for example).

    PS. Also all we keep in mind, that Tcl's array is not an array in Perl's terminology, its a hash.

    Best regards,
    Courage, the Cowardly Dog

      Thanks Courage. You were right, I had gotten off track. I was developing my new GUI elements in pure embedded TCL. After your comment, I stopped and re-assessed my design, ultimately reworking it to be primarily perl/tk syntax.

      However, the understanding of TCL has proved quite helpful.

        I completely agree with all your statements.
        Moreover, if you'll delve into internals of perlTk (without Tcl) you will see more complicated things than just dealing with Tcl syntax, but dealing with Tcl within Tcl::Tk module isn't hard, rather interesting.

        BTW it appeared I needed similar tied hashes recently, so I made them work, at least in a first approximation. You can watch that at CVS http://cvs.sourceforge.net/viewcvs.py/tcltkce/#dirlist or wait for next CPAN release, which is hopefully will be within a week.

        Best regards,
        Courage, the Cowardly Dog

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://423594]
Approved by holli
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-12-18 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (51 votes), past polls