Regarding Storable, the error message is indicating that the binary data it is trying to retrieve was written by Storable version 35.114. Since current version is 2.8, it seems most likely that you are trying to read corrupt data.

I wrote a small test using Storable and it appears to work.

use strict; use warnings; use MLDBM qw(DB_File Storable); use Devel::Peek; use Encode; use FreezeThaw; no warnings 'utf8'; $| = 1; tie my %data, 'MLDBM', 'testmldbm' or die $!; my $string = "a string with a wide character: \x{0100}"; Dump($string); #my $fstring = FreezeThaw::freeze($string); $data{string} = $string; print "$data{string}\n";

It produced the following output, but cut-and-paste seems to have mangled the wide character. It looks like a capital A with a bar above it on my terminal:

SV = PV(0x9766470) at 0x964eae8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK,UTF8) PV = 0x97a5190 "a string with a wide character: \304\200"\0 [UTF8 "a + string with a wide character: \x{100}"] CUR = 34 LEN = 36 a string with a wide character: Ā

Changing the script to use FreezeThaw, it reproduces your error. This appears to be a limitation of DB_File. Apparently FreezeThaw passes the wide characters through to DB_File while Storable does not.

Maybe you can use FreezeThaw with a filter, something like the following:

use strict; use warnings; use MLDBM qw(DB_File FreezeThaw); use Devel::Peek; use Encode; use FreezeThaw; no warnings 'utf8'; use Data::Dumper; use DBM_Filter; $| = 1; my $db = tie my %data, 'MLDBM', 'testmldbm' or die $!; print Dumper($db->{DB}); $db->{DB}->Filter_Push('utf8'); if($db->{DB}->can('Filter_Push')) { print "can Filter_Push\n"; } my $string = "a string with a wide character: \x{0100}"; Dump($string); $data{string} = $string; print "$data{string}\n";

With the filter added, this test script does not produce the Wide character error - it seems to work.


In reply to Re: MLDBM and UTF-8 by ig
in thread MLDBM and UTF-8 by skazat

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.