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

haha.. thanks for the push in the correct direction!
 
Anyways, this isn't a homework problem, let me assure you of that straight away. What I'm doing is an online hockey pool for my work.
 
Currently, it takes the picks that a certain user made out of a data file and assigns a total amount of "points" to the user based on how many points their players have gotten (which is determined completely independantly from this part of the script). This value is stored in an array at this point, because the user ID is, at this point, the array index of the amount of "points." A hash here is useless (right?).
 
Anyways, after all the "points" values for all the users are set into the array, I think it'd be best to put these values into a hash that also holds the user id, and then sort the hash by the "points" values.
 
Perhaps there's something wrong with my reasoning?
 
I'll come clean: I've only be using PERL for 3 days now, and I've only been programming for about a year or so. That's why I tried to explain it more in a mathematical light than a programming one.
 
Thanks for your help! I'll be setting up an account shortly.

Replies are listed 'Best First'.
Re: Re: Re: hash creation.
by chipmunk (Parson) on Jan 03, 2001 at 20:51 UTC
    If I've got a grasp on your problem, what you want to do is sort a list of IDs by their associated point values. You certainly could do that with a hash, where the IDs are keys and the points are values, but given your set of IDs you don't need to; an array would work well for the whole process.
    #!/usr/local/bin/perl -w use strict; my @scores = ( undef, undef, undef, # skip IDs 0, 1, and 2 7, 28, 19, 3, 36, ); my @ids_by_score = sort { $scores[$b] <=> $scores[$a] } # higher scores first 3 .. $#scores; # IDs 3 to max ID print "ID: Score\n"; for my $id (@ids_by_score) { printf "%2d: %5d\n", $id, $scores[$id]; }
    The main difference is that you get the list of IDs as 3 .. $#scores, instead of with keys(%scores) if it were a hash.
      Hey! It worked! Thanks a million to *everyone* who helped with this. And, btw, you're correct -- office gambling sure is getting high-tech.