Hash::Rename - Rename hash keys
use Hash::Rename; my %hash = ( '-noforce' => 1, scheme => 'http' ); hash_rename %hash, code => sub { s/^(?!-)/-/ };
Using this module you can rename a hash's keys in place.
This function is automatically exported. It takes a hash to rename and another hash of instructions on how to rename they keys.
The syntax is like this:
hash_rename %hash, key1 => 'value1', keys2 => 'value2';
The following instructions are supported:
hash_rename %hash, prepend => '-';
The given value is prepended to each hash key.
hash_rename %hash, append => '-';
The given value is appended to each hash key.
hash_rename %hash, code => sub { s/^(?!-)/-/ };
Each hash key is localized to $_ and subjected to the code. Its new value is the result of $_ after the code has been executed.
$_
If present and set to a true value, the resulting keys are checked for duplicates. hash_rename() will die if it detects a duplicate resulting hash key. They keys of the hash to change are processed in alphabetical order.
hash_rename()
If several instructions are given, they are procesed in the order in which they are described above. So you can have:
hash_rename %hash, prepend => '-', append => '=';
If you talk about this module in blogs, on del.icio.us or anywhere else, please use the hashrename tag.
hashrename
This document describes version 0.01 of Hash::Rename.
No bugs have been reported.
Please report any bugs or feature requests to <bug-hash-rename@rt.cpan.org>, or through the web interface at http://rt.cpan.org.
<bug-hash-rename@rt.cpan.org
See perlmodinstall for information and options on installing Perl modules.
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you. Or see <http://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.
Marcel Grünauer, <marcel@cpan.org>
<marcel@cpan.org>
Copyright 2007 by Marcel Grünauer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Hash::Rename, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::Rename
CPAN shell
perl -MCPAN -e shell install Hash::Rename
For more information on module installation, please visit the detailed CPAN module installation guide.