We recently needed a utility to tell us what state or province a telephone area code came from. This took about five minutes (the hardest part was finding the data itself).
=head1 NAME
area_code.pl - What state/province is this area code from?
=head1 SYNOPSIS
perl area_code.pl [area_code]
=head1 AUTHOR
tim allen (zeno@timallen.org)
=cut
#!/usr/bin/perl
use strict;
# get the area code from the user
# User can either enter an area code on the command line or
# be prompted for it.
my $area_code;
if (!$ARGV[0]) {
print "Input an area code: ";
$area_code = <STDIN>;
} else {
$area_code = $ARGV[0];
}
chomp($area_code);
# if the user enters nothing, exit.
if (!$area_code) {exit};
# loop through list of states/provinces
LISTING: while(<DATA>) {
# store the state/province and list of area codes
m/([^\d]+)(.*)\s?/;
my $state=$1;
my $numbers=$2;
if ($numbers =~ m/$area_code/) {
print "$area_code: $state\n";
# once we have a match, don't continue
# through the whole list
last LISTING;
}
}
__DATA__
Alabama 205 251 256 334
Alaska 907
Arizona 480 520 602 623 928
Arkansas 501 870
California 209 213 310 323 408 415 510 530 559 562 619 626 650 661 707
+ 714 760 805 818 831 858 909 916 925 949
Colorado 303 719 720 970
Connecticut 203 860
Delaware 302
District of Columbia 202
Florida 305 321 352 386 407 561 727 786 813 850 863 904 941 954
Georgia 229 404 478 678 706 770 912
Hawaii 808
Idaho 208
Illinois 217 309 312 618 630 708 773 815 847
Indiana 219 317 765 812
Iowa 319 515 563 641 712
Kansas 316 620 785 913
Kentucky 270 502 859 606
Lousiana 225 318 337 504 985
Maine 207
Maryland 240 301 410 443
Massachusetts 339 351 413 508 617 774 781 857 978
Michigan 231 248 313 517 616 734 810 906 989
Minnesota 218 320 507 612 651 763 952
Mississippi 228 601 662
Missouri 314 417 573 636 660 816
Montana 406
Nebraska 308 402
Nevada 702 775
New Hampshire 603
New Jersey 201 609 732 856 908 973
New Mexico 505
New York 212 315 347 516 518 607 631 646 716 718 845 914 917
North Carolina252 336 704 828 910 919 980
North Dakota701
Ohio 216 234 330 419 440 513 614 740 937
Oklahoma 405 580 918
Oregon 503 541 971
Pennsylvania 215 267 412 484 570 610 717 724 814 878
Rhode Island 401
South Carolina 803 843 864
South Dakota 605
Tennessee 423 615 731 865 901 931
Texas 210 214 254 281 361 409 469 512 682 713 806 817 830 832 903 915
+936 940 956 972 979
Utah 435 801
Vermont 802
Virginia 434 540 571 703 757 804
Washington 206 253 360 425 509
West Virginia 304
Wisconsin 262 414 608 715 920
Wyoming 307
Alberta 403 780
British Columbia 250 604
Manitoba 204
Newfoundland 709
New Brunswick 506
Northwest Territories 867
Nova Scotia 902
Nunavut 867
Ontario 289 416 519 613 647 705 807 905
Prince Edward Island 902
Quebec 418 450 514 819
Saskatchewan 306
Yukon Territory 867
Guam 671
Northern Mariana Islands 670
Puerto Rico 787 939
US Virgin Islands 340
Anguilla 264
Antigua & Barbuda 268
Bahamas 242
Barbados 246
Bermuda 441
British Virgin Islands 284
Cayman Islands 345
Dominica 767
Dominican Republic 809
Grenada & Carriacou 473
Jamaica 876
Montserrat 664
Nevis & St. Kitts 869
St. Lucia 758
St. Vincent & The Grenadines 784
Trinidad & Tobago 868
Turks & Caicos 649
American Samoa 684
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|