in reply to Re^2: using TIEHASH as wrapper/proxy, while avoiding recursion and warnings
in thread using TIEHASH as wrapper/proxy, while avoiding recursion and warnings
I wanted to be able to tie the original variable while changing the original data.
I see. I remember that when I tried something similar to that with tied filehandles, I got Perl to segfault, so I'm not sure if tie is meant to be used that way.
It's not always possible to replace the monitored variable with a proxy, you just want to attach the magic directly.
That's probably true, but I imagine it wouldn't be too difficult to refactor the code in question from using a hash to a hashref?
Otherwise, if this is just for debugging, you could use refaliasing to replace the target hash with the tied hash? (though to unite you'd probably have to keep a reference to the original hash around)
use warnings; use strict; use feature 'refaliasing'; use Data::Dump; use Tie::Subset::Hash; my %hash; @hash{"a".."e"} = 41..45; dd \%hash; tie my %hash2, 'Tie::Subset::Hash', \%hash, ['b']; \%hash = \%hash2; dd \%hash; __END__ Aliasing via reference is experimental at foo.pl line 13. { a => 41, b => 42, c => 43, d => 44, e => 45 } { # tied Tie::Subset::Hash b => 42, }
|
---|