I have a compound hashref as follows
my $ch = {
k1 => [ { k=>1 }, { m=>2 } ],
k2 => [ { l=>90}, ... ],
};
Hash::Util::lock_hashref_recurse($ch)
does not effectively lock these values..
@{$ch->{k1}}[0]->{k} = 'New value';
is allowed ! How do i lock such a hashref completely ?
Hashtab is supported as a Windows shell extension and a Mac Finder plugin' and is a popular app in the OS & Utilities category. There are more than 50 alternatives to Hashtab for a variety of platforms, including Windows, Linux, Mac, BSD and PortableApps.com.
HashTab supports many hash algorithms such as MD5, SHA1, SHA2, RipeMD, HAVAL and Whirlpool. Hashtab is supported as a Windows shell extension and a Mac Finder plugin' and is a popular app in the OS & Utilities category.
RHash (Recursive Hasher) is a console utility for computing and verifying hash sums of files. It supports CRC32, MD4, MD5, SHA1, SHA256, SHA512, Tiger, DC++ TTH, BitTorrent BTIH, ED2K, AICH, GOST R 34.
According to the documentation:
This method only recurses into hashes that are referenced by another hash. Thus a Hash of Hashes (HoH) will all be restricted, but a Hash of Arrays of Hashes (HoAoH) will only have the top hash restricted.
And you have a Hash of Arrays of Hashes
use strictures;
use Hash::Util qw(lock_hash);
use Data::Visitor::Callback qw();
my $ch = {
k1 => [{k => 1}, {m => 2}],
k2 => [{l => 90},],
};
Data::Visitor::Callback->new(
hash => sub {
lock_hash %{ $_ };
return $_;
}
)->visit($ch);
$ch->{k1}[0]{k} = 'New value';
__END__
Modification of a read-only value attempted at …
Hash::Util
itself provides you a low-level function that you can replicate in Perl without XS functionality: i.e. lock_hash
/ lock_hashref
. The rest of functionality you need is a simple hash traversal and can be easily implemented manually. Traverse through nested references while keeping list of visited ones and list of found hashes and then run loop over that found list with lock_hashref
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With