in reply to data structure problem
If you were to store this in a relational database, you could just dump it in a table and build three indices on top of it. Well, we can do something similar in Perl (except that our indices are not at all suitable for range queries), using hashes for the indices.
Here's some example code (assuming the codes and countries are unique, but currencies aren't).
#!/usr/bin/perl -w use strict; use warnings 'all'; my (%code, %country, %currency); while (<DATA>) { my $info = [split]; $code {$info -> [0]} = $info; $country {$info -> [1]} = $info; push @{$currency {$info -> [2]}} => $info; } sub info_by_code { my $code = shift; $code {$code} } sub info_by_country { my $country = shift; $country {$country} } sub info_by_currency { my $currency = shift; @{$currency {$currency}} } print "Code for Germany is ", info_by_country ("GER") -> [0], "\n"; print "People pay in Euros in ", join (", " => map {$_ -> [1]} info_by_currency ("EUR")), "\n"; __END__ US USA USD CA CAN CND DE GER EUR IT ITA EUR FR FRA EUR NL NET EUR BE BEL EUR CH SWI SFR $ ./countries Code for Germany is DE People pay in Euros in GER, ITA, FRA, NET, BEL $
Abigail
|
---|