go ahead... be a heretic | |
PerlMonks |
Infinite recursion for iterator of tied hash with perldbmfilter for filter_fetch_keyby Pickwick (Beadle) |
on Sep 08, 2014 at 21:29 UTC ( [id://1099905]=perlquestion: print w/replies, xml ) | Need Help?? |
Pickwick has asked for the wisdom of the Perl Monks concerning the following question: Dear wise monks, I have a tied hash in Perl which uses SDBM_File and I need to do some character encoding conversions when storing or fetching values. I followed the documentation of perldbmfilter and in general it seems to work: I get the results from the hash properly encoded like expected and it stores the byte values for my encoding in the file, if I check using a hex editor. What is not working is any kind of iteration over all elements of the hash, either using keys(...) or each(...) or things like Dumper(...) or even a simple copy operation to another hash. What I always get is an infinite recursion, it seems like the used iterator doesn't ever get to it's end and if I use each(...) and print the iterated values they are repeated all over. I hunted the problem down to the use of filter_fetch_key and the charset conversion I'm doing there: If I comment filter_fetch_key the iteration works again or if I change the called method to not do anything, but only do a "return shift;" Either of both solves my problem, but I need to use filter_fetch_key to send the caller properly encoded strings.
If I uncomment "return shift", the iteration works, but commented like above it doesn't. I guess it has something to do what happens to $_, but I have no idea, as windows2utf just copies the given data and does some character encoding. This works the same way for storing keys and values and even for fetching values. Only keys are the problem and only if I do an iteration, not if I directly ask for specific keys. Any hints on what I'm doing wrong? Thanks!
Back to
Seekers of Perl Wisdom
|
|