in reply to Re: Re: PAR and Tk
in thread PAR and Tk
(also comment out the "print" statement in "get_def" -- you don't need that one anyway)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++; } }
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 | |
by graff (Chancellor) on May 18, 2004 at 00:58 UTC |