Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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)


In reply to Re: Re: Re: PAR and Tk by graff
in thread PAR and Tk by nornagon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-23 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found