SHARYA...h::Util(3pm)

πŸ“¦
version 0.77 Β· 2 versions
  • 0.77 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.77 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

SHARYANTO::Hash::Util β€” it's giving hash utilities, bestie ✨ literally just a lil toolbox for your Perl hashes πŸŽ€


🌸 VERSION 🌸

This doc is describing version 0.77 of SHARYANTO::Hash::Util, which comes from the Perl distribution SHARYANTO-Utils, and it was released on 2015-09-04. Yeah she's an elder but she still slays πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so picture this, you just need to rename one key:

use SHARYANTO::Hash::Util qw(rename_key);
my %h = (a=>1, b=>2);
rename_key(\%h, "a", "alpha"); # %h = (alpha=>1, b=>2)

boom. done. iconic. πŸ‘‘


✨ FUNCTIONS ✨

🌈 rename_key(\%hash, $old_key, $new_key)

Renames a key, no cap. Underneath it's basically $hash{$new_key} = delete $hash{$old_key} but with a couple extra lil checks sprinkled on top 🧚 It's a shortcut for exactly this:

die unless exists $hash{$old_key};
die if     exists $hash{$new_key};
$hash{$new_key} = delete $hash{$old_key};

so like, it'll die if the old key isn't there, and it'll also die if the new key is already taken β€” because we are NOT about that overwrite life πŸ™ˆ

πŸŽ€ replace_hash_content($hashref, @pairs) => $hashref

Replaces the content in $hashref with @list. Returns $hashref. And the important part: it does NOT make a new hashref object β€” so it's different from doing $hashref = {new=>"content"} πŸ’€

bestie. listen. Do not use this function. In Perl you can literally just do %$hashref = @pairs. I put the function here as a reminder. That's it. That's the whole thing. 😭

πŸ‘€ SEE ALSO πŸ‘€

SHARYANTO β€” go look at her, she's the mom of this whole situation 🫢


🏠 HOMEPAGE 🏠

Wanna visit the project's homepage? It's right here, come thru:

<https://metacpan.org/release/SHARYANTO-Utils>


πŸ“ SOURCE πŸ“

The source repository lives at:

<https://github.com/perlancar/perl-SHARYANTO-Utils>

go peek, go star it, go be nosy πŸ’œ


πŸ’€ BUGS πŸ’€

Found a bug? Got a feature request? Please report it on the bugtracker website:

<https://rt.cpan.org/Public/Dist/Display.html?Name=SHARYANTO-Utils>

And when you submit a bug or a request, please include a test-file β€” or a patch to an existing test-file β€” that illustrates the bug or the desired feature. fr fr, that's the whole ask πŸ™


πŸ‘‘ AUTHOR πŸ‘‘

perlancar &lt;perlancar@cpan.org&gt;


This software is copyright (c) 2015 by 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. so like, go wild but respectfully ✨


and that's a wrap on SHARYA...h::Util(3pm) β€” this page came to you via perl v5.34.0, dated 2022-06-17. ty for coming to my ted talk, mwah πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from