cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
but accessing that would leave the keys associated with the same values. I want to randomly reassign the keys to different values already in the hash. So if the original wasuse List::Util qw(shuffle); ... foreach my $k (shuffle keys %foo) { ... }
I could end up with%hash = ( "a" => 1, "b" => 2, "c" => 3, "d" => 4 };
%hash = ( "c" => 1, "d" => 2, "a" => 3, "b" => 4 };
I can imagine how to do that in an inelegant way, but was wondering if there is an elegant way.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Randomly reassign hash keys
by poj (Abbot) on Apr 26, 2017 at 17:07 UTC | |
by Anonymous Monk on Apr 26, 2017 at 18:20 UTC | |
by AnomalousMonk (Archbishop) on Apr 26, 2017 at 22:45 UTC | |
by jdporter (Paladin) on Apr 28, 2017 at 02:14 UTC | |
by Eily (Monsignor) on Apr 26, 2017 at 17:20 UTC | |
by perldigious (Priest) on Apr 26, 2017 at 19:18 UTC | |
by vrk (Chaplain) on Apr 27, 2017 at 09:35 UTC | |
by Anonymous Monk on Apr 27, 2017 at 22:27 UTC | |
Re: Randomly reassign hash keys
by thomas895 (Deacon) on Apr 26, 2017 at 16:53 UTC | |
Re: Randomly reassign hash keys
by thanos1983 (Parson) on Apr 26, 2017 at 18:02 UTC | |
Re: Randomly reassign hash keys
by stevieb (Canon) on Apr 26, 2017 at 16:57 UTC | |
Re: Randomly reassign hash keys
by kcott (Archbishop) on Apr 27, 2017 at 05:50 UTC | |
Re: Randomly reassign hash keys
by BillKSmith (Monsignor) on Apr 26, 2017 at 19:56 UTC |