Perl/Shell/Python Knowledge Sharing

Perl, shell, python Interview Questions and Answers and quiz

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;
Posted by perlknowledge at 10:37 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: Interview question

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Search This Blog

Labels

  • perl (225)
  • Python (25)
  • Quiz (8)
  • C (6)
  • Linux (6)
  • AWS (3)
  • PHP (1)
  • Vi (1)

Blog Archive

  • ►  2026 (33)
    • ►  September (33)
  • ►  2017 (1)
    • ►  March (1)
  • ►  2014 (23)
    • ►  November (1)
    • ►  July (1)
    • ►  June (5)
    • ►  April (4)
    • ►  March (6)
    • ►  January (6)
  • ►  2013 (8)
    • ►  December (4)
    • ►  June (3)
    • ►  March (1)
  • ►  2012 (5)
    • ►  November (1)
    • ►  January (4)
  • ▼  2011 (215)
    • ►  November (5)
    • ►  September (1)
    • ▼  August (5)
      • How to Initialize or Clear an Array in Perl
      • How to shuffle the values in a hash?
      • How to Validate an IPv4 Address in Perl Using Regu...
      • perl - Objects, Modules and Packages
      • Perl References
    • ►  July (11)
    • ►  June (6)
    • ►  May (17)
    • ►  April (16)
    • ►  March (14)
    • ►  February (9)
    • ►  January (131)
  • ►  2010 (42)
    • ►  December (42)
© 2026 Purandaran Vudhayagiri. All Rights Reserved.. Theme images by Flashworks. Powered by Blogger.