> I'm using the Storable module to save and load a hash tree. I also
want to use the 
> Hash::Case::Lower module to make my hash case insensitive. I can't
figure out how to tie a 
> hashref to the Hash::Case::Lower module and load data into it with
Storable. I tried 
> something like:
> 
> use Hash::Case::Lower;
> use Storable;
> 
> tie my(%realhash), 'Hash::Case::Lower';
> my $hashref = \%realhash;
> $hashref = retrieve('somefile');
> 
> This causes $hashref to be assigned to the anonymous hash returned
from retrieve() so that 
> it no longer points to the tied hash. It is then no longer case
insensitive. How can I 
> make this work?
> 

You need to tie your hash after retrieving the values.  Or provide the
values as part of the tie invocation. I haven't worked with Hash::Case
before, but it looks from the docs that you can provide your retrieved
hashref as the 'VALUES'.  For instance,

my $thawed = retrieve('somefile');
tie my(%realhash), 'Hash::Case::Lower', $thawed;

That or you would have to walk the structure of what you have installed
and add each piece to the hash again, or use a hash slice to do it.

@realhash{ keys %$thawed } = @$thawed{ keys %$thawed };  # untested!

This should guarantee that the TIE methods are invoked properly.

But then I am just guessing :-)...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to