in reply to Re: Re: Re: hash creation.
in thread hash creation.

ok :)
 
First off, thanks a lot for the help. As I've mentioned, I'm still really new to this stuff, and places like this make things a lot easier.
 
Now, to the dirty stuff. Yes, the sorting of the hash is no problem. I do own a book called "mastering PERL" (just went out and bought it yesterday), but I can't seem to find any help on setting the hash for this case.
 
All I want to know is how to set the hash properly, having two arrays (one holding the UIDs and one holding the "points values) of an undefined length, so that the UIDs and the "points" values will be put into the hash.
 
After that's set, I have the sort under control. I just need to know how to properly set that hash.
 
For arrays, there's push; is there anything like this for hashes?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: hash creation.
by salvadors (Pilgrim) on Jan 03, 2001 at 20:25 UTC
    Use a hash slice: @hash{@uids} = @points;

    my @uids = (0..9); my @points = qw/1 3 2 5 10 3 2 1 3 0/; my %hash; @hash{@uids} = @points; foreach (sort { $hash{$b} <=> $hash{$a} } keys %hash) { print "$_: $hash{$_}\n"; }

    Tony