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?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |