Second Perl Experiment
After a bit of reading online and book reading (Learning Perl 2nd Edition), I came up with this;
#!/usr/bin/perl # Revision 1 - 09-03-09 1530 # Countr Code list, stdin, perl # SRC for codes: http://www.kropla.com/dialcode.htm use Term::ANSIColor qw(:constants); $Term::ANSIColor::AUTORESET = 1; #reset colors after each line print GREEN "Please enter the country code you are trying to look up.\n"; $cc = <STDIN>; chomp $cc; if ($cc eq "1") { print GREEN "United States of America or Canada.\n"; } elsif ($cc eq "93") { print RED "Afghanistan.\n"; } elsif ($cc eq "355") { print RED "Albania.\n"; } elsif ($cc eq "213") { print RED "Algeria.\n"; } elsif ($cc eq "1684") { print RED "American Samoa.\n"; } elsif ($cc eq "376") { print RED "Andorra.\n"; } elsif ($cc eq "244") { print RED "Angola.\n"; } elsif ($cc eq "1268") { print RED "Antigua.\n"; } elsif ($cc eq "54") { print RED "Argentina.\n"; } elsif ($cc eq "374") { print RED "Armenia.\n"; } elsif ($cc eq "297") { print RED "Aruba.\n"; } elsif ($cc eq "247") { print RED "Ascension.\n"; } elsif ($cc eq "61") { print RED "Australia.\n"; } elsif ($cc eq "672") { print RED "Australian Extrernal Territories.\n"; } elsif ($cc eq "43") { print RED "Austra.\n"; } elsif ($cc eq "994") { print RED "Azerbaijan.\n"; } elsif ($cc eq "1242") { print RED "Bahamas.\n"; } elsif ($cc eq "973") { print RED "Bahrain.\n"; } elsif ($cc eq "880") { print RED "Bangladesh.\n"; } elsif ($cc eq "1246") { print RED "Barbados.\n"; } elsif ($cc eq "1268") { print RED "Barbuda.\n"; } elsif ($cc eq "375") { print RED "Belarus.\n"; } elsif ($cc eq "32") { print RED "Belgium.\n"; } elsif ($cc eq "501") { print RED "Belize.\n"; }
Some of you may find this to be pretty elementary, but lets see what I can come up with in the next day or two. Essentially all this does is looks for a country that matches the code you put in. It does not include all countries, but I think I got the idea of elsif in perl.