Perl/Shell Knowledge Sharing
Perl Interview Questions and Answers
Thursday, August 4, 2011
How to shuffle the values in a hash?
use List::Util qw(shuffle);
%hash = (this => 0,
is => 1,
a => 2,
test => 3);
my @values = shuffle(values %hash);
map { $hash{$_} = shift(@values) } (keys %hash);
print "$_\t$hash{$_}\n" foreach keys %hash;
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment