Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

Replies are listed 'Best First'.
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

    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 or wait for next CPAN release, which is hopefully will be within a week.

        Best regards,
        Courage, the Cowardly Dog

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://423594]
Approved by holli
Front-paged by Courage
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2018-01-22 18:22 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (235 votes). Check out past polls.