in reply to Re: Re: PAR and Tk
in thread PAR and Tk

Hrm. I could see character encoding being an issue if you were looking up dictionary entries in some language other than English, but since you're not doing that, you may need to add some debugging output, so you can compare the "original" output (via "perl your-tk-script.pl") against the "compiled" output. Changing "get_words" to something like this might be instructive:
sub get_words { my $dict = Net::Dict->new('dict.org'); my $term = $wordbox->get; my $h = $dict->define($term); my $result; my $n = 0; #(update: left line this out earlier, but see below) foreach my $i (@{$h}) { my ($db, $def) = @{$i}; print join "", "$db: $term:\n", map { sprintf("%.2x $_\n",ord( +)) } split( //, $def ); $list->insert('end', "$db: $term"); $defs[$n] = $def; $n++; } }
(also comment out the "print" statement in "get_def" -- you don't need that one anyway)

When you run each version of the script (interpreted and compiled), get the same term for each run (e.g. "autotelic" -- my favorite word -- which has a mercifully short output), redirect stdout to a distinct file, then diff the two files. This will tell you at least two things: (1) whether you're getting the same number of characters from each version, and (2) whether there is any systematic bit-wise relation between the characters of the two versions (e.g. for some reason, the compiled version might just be setting the high bit of each character, though I can't imagine how this would come about).

Apart from that, your code has a problem when I try to put in a second term for definition: in get_word, you reset the array index "$n" for the listbox contents to zero, but you don't remove the prior contents of the listbox.

I would suggest that you declare a global index counter for @defs (e.g. put  my $ndefs = 0; at the top, and use $ndefs instead of $n in get_words), and never set it back to zero. That way, a user can have multiple terms in the listbox at the same time. (Then you might need a button to delete selected items from the listbox, and/or clear the listbox contents.)

Thanks for posting your code -- it was my first real introduction to Net::dict, and I could have a lot of fun with that...

(updated the title to reflect the name of the thread)

Replies are listed 'Best First'.
Re: Re: Re: Re: PAR and Tk
by nornagon (Acolyte) on May 17, 2004 at 05:41 UTC
    Um, a problem. Either 1) I don't know what diff is, or 2) it's a unix/linux program, and I'm running a win32 machine =/

    No problems, Net::Dict is really easy :)

    {update}: Ok, I added in the get_words sub you gave me, and the output is the same for the compiled and interpreted versions. However, actually viewing the characters is still a problem.

      Yes, "diff" is a unix program, and there are win32 ports available for free (cf. Cygwin, GNU, ATT Research Labs, among others); another unix program (also ported) is "paste", which would let you put the two files side-by-side.

      Anyway, you've already compared the files, and they are the same. (I was afraid that might happen...) Maybe flyingmoose's more recent reply has the part you really need -- one can only hope. At least you've proven that there was no pollution of the data up to that point -- the problem involves one of the Tk modules.