Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!sol.ctr.columbia.edu!lll-winken!uunet!stephsf!wengland From: wengland@stephsf.stephsf.com (Bill England) Newsgroups: comp.lang.perl Subject: Re: The best way to search an array ? Keywords: detab Message-ID: <452@stephsf.stephsf.com> Date: 13 Dec 90 00:51:46 GMT References: <443@stephsf.stephsf.com> <1990Dec3.035541.24184@agora.uucp> Organization: Stephen Software Systems, Inc., Tacoma WA Lines: 60 In article <1990Dec3.035541.24184@agora.uucp> markb@agora.uucp (Mark Biggar) writes: >In article <443@stephsf.stephsf.com> wengland@stephsf.stephsf.com (Bill England) writes: > [...] >if you don't need the full names just set the associated array value to 1. >this is a very good way to go if the search set is generated by your >program. If you have a very large constant search set using a dbm file >for it may be the best way to go. > >-- >Perl's maternal uncle >Mark Biggar Thanks for the ideas. I've attached the resulting routine to the end of this article. I'm not entirely comforatable with referancing an array that has been undef'ed yet. ;-) ----- vrfy_state.pl ----- package state_check; ## # Copyright(c) 1991, Stephen Software Systems, Inc. # This software may be modified and copied under the terms of # the GNU Public License. # # State Check Library # Given a USA $state determine if it is correct. # Return a postmaster approved two letter abreviation. # $state may be either states full name or two letter abreviation. # # WSE Created Wed Nov 28 14:08:25 PST 1990 # # Send problems, suggestions, errors, and # heresys to support@stephsf.COM. ## %st_name = split(/!/, 'ALASKA!AK!ALABAMA!AL!ARKANSAS!AR!ARIZONA!AZ!CALIFORNIA!CA!COLORADO!CO!CONNECTICUT!CT!DELAWARE!DE!FLORIDA!FL!GEORGIA!GA!HAWAII!HI!IOWA!IA!IDAHO!ID!ILLINOIS!IL!INDIANA!IN!KANSAS!KS!KENTUCKY!KY!LOUISIANA!LA!MASSACHUSETTS!MA!MARYLAND!MD!MAINE!ME!MICHIGAN!MI!MINNESOTA!MN!MISSOURI!MO!MISSISSIPPI!MS!MONTANA!MT!NEBRASKA!NB!NORTH CAROLINA!NC!NORTH DAKOTA!ND!NEW HAMPSHIRE!NH!NEW JERSEY!NJ!NEW MEXICO!NM!NEVADA!NV!NEW YORK!NY!OHIO!OH!OKLAHOMA!OK!OREGON!OR!PENNSYLVANIA!PA!RHODE ISLAND!RI!SOUTH CAROLINA!SC!SOUTH DAKOTA !SD!TENNESSEE!TN!TEXAS!TX!UTAH!UT!VIRGINIA!VA!VERMONT!VT!WASHINGTON!WA!WISCONSIN!WI!WEST VIRGINIA!WV!WYOMING!WY'); %st_abr = split(/( )/,'AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NB NC ND NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY '); ## # State_Check # In: usa_state (two letter abreviation, or full state name ) # Out: () || ST(Usa two letter state abreviation) ## sub main'State_Check { local($state) = @_; $state =~ y/a-z/A-Z/; return $state if defined($st_abr{$state}); return $st_name{$state} if defined($st_name{$state}); return (); } -- +- Bill England, wengland@stephsf.COM -----------------------------------+ | * * H -> He +24Mev | | * * * ... Oooo, we're having so much fun making itty bitty suns * | |__ * * ___________________________________________________________________|