Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

scrambling keys of a hash (was: Fellow monks;)

by Sihal (Pilgrim)
on Aug 27, 2002 at 09:13 UTC ( [id://193106]=perlquestion: print w/replies, xml ) Need Help??

Sihal has asked for the wisdom of the Perl Monks concerning the following question:

I have a simple question yet I can't seem to find an answer: what is the simplest, fastest way to scramble the keys of an hash ? ( I'm getting a hash wher querying a database, and I wanna scramble it ) ... Thanks a lot for your help

Edit kudra, 2002-08-27 Changed title

  • Comment on scrambling keys of a hash (was: Fellow monks;)

Replies are listed 'Best First'.
Re: Fellow monks;
by JaWi (Hermit) on Aug 27, 2002 at 09:23 UTC
    What exactly do you mean by ``scrambling'': randomizing it, or encrypting it so nobody can pear into its contents?

    In the first case you probably want to have a look at Data::Random, which you can use like this snippet:

    #!/usr/bin/perl -w use strict; use Data::Random qw(:all); use Data::Dumper; my @keys = qw(aap noot mies bert ernie klaas tentamen college); print "Before:\n" . Dumper( @keys ) . "\n"; my @random_set = rand_set( set => \@keys, size => $#keys + 1 ); print "After:\n" . Dumper( @random_set ) . "\n";

    For encryption you can use various ways Crypt::Des for example.

    Good Luck!

    Changed the name of refered module to the correct one & added size operand to `rand_set' to get complete input set back (in random order)

    -- JaWi

    "A chicken is an egg's way of producing more eggs."

      Wow! I didn't know about this module Data::Rand. That's exactly what I needed, thanx.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://193106]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-25 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found