importing upstream 1.41
[Locale-SubCountry.git] / examples / demo.pl
1 #!/usr/bin/perl
2
3 # demo script for Locale::SubCountry
4
5 use strict;
6 use Locale::SubCountry;
7
8 # For every country
9 #    list the country name
10 #    if any subcountries, list each code and full name on a new line
11
12 my $world = new Locale::SubCountry::World;
13 my @all_countries  = $world->all_full_names;
14
15 my %all_letters;
16 foreach my $country ( sort @all_countries )
17 {
18     print "\n\n$country\n";
19     my $current_country = new Locale::SubCountry($country);
20   
21     # Are there any sub countires?
22     if ( $current_country->has_sub_countries )
23     {
24         # Get a hash, key is sub country code, value is full anme, such as 
25         # SA => 'South Australia', VIC => 'Victoria' ...
26         my %sub_countries_keyed_by_code  = $current_country->code_full_name_hash;
27         foreach my $code ( sort keys %sub_countries_keyed_by_code )
28         {
29             printf("%-3s : %s\n",$code,$sub_countries_keyed_by_code{$code});
30         }               
31     }
32 }