FoxtrotUniform has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm writing Yet Another Guitar Chord Finder(tm), and as such I want to be able to map easily between note names and their positions in the chromatic scale. I want to be able to find that A is the first note on the chromatic, and that the second note on that scale is A#. My first instinct was to use a hash, but that only gets me one direction. I can always build a second "backwards" hash:
my %position_of = ( 'A' => 1, 'A#' => 2, # ... ); my %note_at = (); for my $note (keys %position_of) { $note_at{$position_of{$note}} = $note; }
but I don't really like the idea of having two hashes that express basically the same thing. (Semantically, I know, the hashes don't, but the data are bijective, and I should be able to do it with one structure, dammit!)
Two hashes probably isn't a bad WTDI, but is there a better way?
--
F
o
x
t
r
o
t
U
n
i
f
o
r
m
Found a typo in this node? /msg me
The hell with paco, vote for Erudil!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Bijective data association structure? (1 hash)
by tye (Sage) on Feb 27, 2003 at 19:26 UTC | |
Re: Bijective data association structure?
by jasonk (Parson) on Feb 27, 2003 at 19:20 UTC | |
Re: Bijective data association structure?
by jlongino (Parson) on Feb 27, 2003 at 19:35 UTC | |
Re: Bijective data association structure?
by Ctrl-z (Friar) on Feb 28, 2003 at 00:08 UTC |