Okay, so here's the deal
I need a data structure that will store 2-7 data points (these points will be numbers from 0-50 with none repeated) in such a way as to preserve the order of the data points, and to make look up on a specific point easy.
I'm going to address the second part first, to make this easy for me, I'm tempted to put these items into a hash and use exists. eg.
sub find_point(){
my $ref = shift;
my %hash = %$ref;
my $key = shift;
if(exists($hash{$key})){
...
}
}
While this would be an ideal solution for finding a key quickly, trying to order the data based on the values associated with those keys seems to be quite a bit of extra effort. Eg.
sub points_list(){
my $ref = shift;
my %hash = %$ref;
my @order;
foreach $item (keys %hash){
@order[int($hash{$item})]=$item;
}
return \@order;
}
Now this wouldn't be so bad, but it may be done on a number of hashes like this. Does anyone see a better way?
==
Kwyjibo. A big, dumb, balding North American ape. With no chin.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.