in reply to Re: DBM modules and unicode keys
in thread DBM modules and unicode keys

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?

Replies are listed 'Best First'.
Re: Re:^2 DBM modules and unicode keys
by demerphq (Chancellor) on Nov 22, 2002 at 15:54 UTC
    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', $_); } );