Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: $str to %hash to @ary

by Limbic~Region (Chancellor)
on Jul 22, 2004 at 22:34 UTC ( [id://376746]=note: print w/replies, xml ) Need Help??


in reply to $str to %hash to @ary

abaxaba,
  • Repeatedly doing hash lookups is slower than doing it once
  • The order appears reversed since as is you can't have two ads with the same weight nor lookup the weight of an add.
Assuming it is ok to reverse the order, I have presented the following unique solution that does not require an array:
#!/usr/bin/perl use strict; use warnings; my $lookup; my %hash = split /:/ , '43:17:21:33:19:23:6:27'; while (my ($key, $val) = each %hash) { $lookup .= pack("C*", ($key) x $val); } print unpack("C", substr($lookup, rand 100, 1));

Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://376746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found