Hi there

My script uses GDBM_FILE and ties a hash to a file on disk as follows

tie(%term_doc_count, "GDBM_File", "term_docCount", GDBM_WRCREAT, 0666);

Then it tries to add to this hash as follows:

$term_doc_count{$stem_term}++;

This seems to be causing a "Wide character in null operation" error when $stem_term equals "today’s" - but the apostrophe in "today's" seems to be a special character

Referring to this thread: http://www.perlmonks.org/?node_id=565560, I gathered that this might be because GDBM cannot handle UTF-8 keys, and using the suggestion from user 'graff' I added the following lines to my code which seem to solve the problem:

my $usable_term = encode( 'utf8', $stem_term ); $term_doc_count{$usable_term}++;

However, I cannot understand why this works. I mean, if GDBM_FILE can't handle utf-8 keys, then why is it that encoding the key as utf-8 and then handing that key to GDBM solves the problem? I'd really prefer to understand the solution to my problem rather than to just use something which works without understanding it. Can anyone help?


In reply to hash tied to GDBM_FILE causes Wide character in null operation by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.