in reply to DBM modules and unicode keys

I think the easiest way to resolve this would be to use DB_File's filter_fetch_key() and filter_store_key() mechanism. Use that to ensure that whatever gets put in gets pulled out the same way, even if it isnt stored internally in the DB the way one might think.

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re:^2 DBM modules and unicode keys
by ph0enix (Friar) on Nov 22, 2002 at 15:03 UTC

    I tried following code without success. Looks like return only octets instead of string...

    (tied %data)->filter_fetch_key( sub { decode('utf8', $_); } ); print join(', ', keys %data), "\n";

    But this code produces correct output

    print join(', ', map { decode('utf8', $_) } keys %data), "\n";

    Another hint?

      Well i would guess that you need to encode the data as you put it in the DB and then decode it when you take it out. The code you have posted suggests that you are trying to extract from a DB created without using an appropriate filter_store_key(). I would delete the db, construct the appropriate store and fetch filters and then try rebuilding it.

      Im sorry I cant help more than that, im not too familiar with the ins and outs of UTF8, but this is definately where I would start to try to solve the problem.

      --- demerphq
      my friends call me, usually because I'm late....

        By reading docs again and again I found my mistake. The $_ variable must be modified instead of returning value, because the return code from the filter is ignored. Thank you

        The correct filtering function is

        (tied %data)->filter_fetch_key( sub { $_ = decode('utf8', $_); } );