perhaps you should consider giving each student a unique id number, and use that as the key for all your data. for instance:
my %id_to_name = ( 1 => 'keith', 2 => 'rob', 3 => 'eric', 4 => 'rob', # etc. ); my %id_to_mark = ( 1 => 90, 2 => 52, 3 => 86, 4 => 71, # etc. );
as long as you can match a unique id to a name, you can address the proper student's marks. if it's not possible to organize your data this way (for instance names are not given in the same order each time,) then you won't be able to implement it this way, using arrays or hashes.

if you're tracking any particular student, you'll need something unique to identify her. if that information is not available in the data, there's no way to do it. if the information is there, find it, and use it for the key in your hash.

if you're not tracking any particular student, and are trending the group as a whole, you can key the hash on the score, keep either a count of students with that score, or an array of student names as hash values. here's an example:

my %scores_to_names = ( 90 => [ 'keith' ], 52 => [ 'rob', 'dave' ], # etc. );
if you find this might be a way to go, look in perldsc (perl data structures cookbook) for examples. and use Data::Dumper to see what your structure looks like, it's really handy.

~Particle ;Þ p.s. if your data is given in the same order every time, perhaps you could implement this using arrays. the unique id would be the position in the array, and the values could be in different arrays, like @names, @marks, etc. or, the data could live in an array of arrays. again, find examples in perldsc. good luck!


In reply to Re: Re: Re: Re: Re: sort hash elements... by particle
in thread sort hash elements... by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.