Acme::CPANModules::HashUtilities - List of modules that manipulate hashes
This document describes version 0.004 of Acme::CPANModules::HashUtilities (from Perl distribution Acme-CPANModules-HashUtilities), released on 2023-10-29.
Most of the time, you don't need modules to manipulate hashes; Perl's built-in facilities suffice. The modules below, however, are sometimes convenient. This list is organized by task.
Hash::Util's hv_store allows you to store an alias to a variable in a hash instead of copying the value. This means, if you set a hash value, it will instead set the value of the aliased variable instead. Copying from Hash::Util's documentation:
hv_store
my $sv = 0; hv_store(%hash,$key,$sv) or die "Failed to alias!"; $hash{$key} = 1; print $sv; # prints 1
Aside from creating restricted hash, Hash::Util also provides routines to get information about hash internals, e.g. hash_seed(), hash_value(), bucket_info(), bucket_stats(), etc.
hash_seed()
hash_value()
bucket_info()
bucket_stats()
Merging hashes is usually as simple as:
my %merged = (%hash1, %hash2, %hash3);
but sometimes you want different merging behavior, particularly in case where the same key is found in more than one hash. See the various hash merging modules:
Hash::Merge
Data::ModeMerge
Hash::Union
Hash::WithDefault
Perl through Hash::Util (a core module) allows you to restrict what keys can be set in a hash. This can be used to protect against typos and for simple validation. (For more complex validation, e.g. allowing patterns of valid keys and/or rejecting patterns of invalid keys, you can use the tie mechanism.)
Reversing a hash (where keys become values and values become keys) can be done using the builtin's reverse (which actually just reverse a list):
reverse
%hash = (a=>1, b=>2); %reverse = reverse %hash; # => (2=>"b", 1=>"a")
Since the new keys can contain duplicates, this can "destroy" some old keys:
%hash = (a=>1, b=>1); %reverse = reverse %hash; # => sometimes (1=>"b"), sometimes (1=>"a")
Hash::MoreUtil's safe_reverse allows you to specify a coderef that can decide whether to ignore overwriting, croak, or whatever else.
safe_reverse
Hash::MoreUtils's slice_* functions.
slice_*
Hash::Subset
Hash::Util::Pick
The tie mechanism, although relatively slow, allows you to create various kinds of "magical" hash that does things whenever you get or set keys.
Author: RJBS
Author: HERMES
Author: PERLANCAR
Author: LONERR
Author: REHSACK
Author: PINE
An Acme::CPANModules::* module, like this module, contains just a list of module names that share a common characteristics. It is a way to categorize modules and document CPAN. See Acme::CPANModules for more details.
Aside from reading this Acme::CPANModules module's POD documentation, you can install all the listed modules (entries) using cpanm-cpanmodules script (from App::cpanm::cpanmodules distribution):
% cpanm-cpanmodules -n HashUtilities
Alternatively you can use the cpanmodules CLI (from App::cpanmodules distribution):
% cpanmodules ls-entries HashUtilities | cpanm -n
or Acme::CM::Get:
% perl -MAcme::CM::Get=HashUtilities -E'say $_->{module} for @{ $LIST->{entries} }' | cpanm -n
or directly:
% perl -MAcme::CPANModules::HashUtilities -E'say $_->{module} for @{ $Acme::CPANModules::HashUtilities::LIST->{entries} }' | cpanm -n
This Acme::CPANModules module also helps lcpan produce a more meaningful result for lcpan related-mods command when it comes to finding related modules for the modules listed in this Acme::CPANModules module. See App::lcpan::Cmd::related_mods for more details on how "related modules" are found.
lcpan related-mods
Please visit the project's homepage at https://metacpan.org/release/Acme-CPANModules-HashUtilities.
Source repository is at https://github.com/perlancar/perl-Acme-CPANModules-HashUtilities.
Acme::CPANModules::OrderedHash
Acme::CPANModules - about the Acme::CPANModules namespace
cpanmodules - CLI tool to let you browse/view the lists
perlancar <perlancar@cpan.org>
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
This software is copyright (c) 2023, 2020 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Acme-CPANModules-HashUtilities
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
To install Acme::CPANModules::HashUtilities, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acme::CPANModules::HashUtilities
CPAN shell
perl -MCPAN -e shell install Acme::CPANModules::HashUtilities
For more information on module installation, please visit the detailed CPAN module installation guide.