There's three approaches the authors could have taken.

The implementers went with the first. It's the only one that allows the module to read any GDBM file, and that's extremely important. That leaves it up to the user to serialise strings of text into strings of bytes by encoding them.

I suppose its constructor could accept an argument specifying an encoding, allowing the user to choose whether he wants the first or second behaviour. I guess the authors didn't consider that, but that's excusable because the module predates Perl's support for strings of non-ASCII text.


Your error is that your string contains the characters

74 6F 64 61 79 2019 73

so one of the characters isn't a byte, yet the module expects bytes.


Note that UTF-8 isn't always produced. Only when garbage (something that isn't a string of bytes) is given.

Literal: "\xC9\x72\x69\x63" String: C9 72 69 63 Stored: C9 72 69 63 Literal: "\N{LATIN CAPITAL LETTER E WITH ACUTE}ric" String: C9 72 69 63 Stored: C9 72 69 63 Literal: "\N{LATIN CAPITAL LETTER E WITH ACUTE}ric\N{RIGHT SINGLE QUOT +ATION MARK}s" String: C9 72 69 63 2019 73 Stored: C3 89 72 69 63 E2 80 99 73 (with warning)

In reply to Re: hash tied to GDBM_FILE causes Wide character in null operation by ikegami
in thread 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.