[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] My little trick for the day




I don't remember seeing this before, but I was pretty proud of thinking of
it...

I've got a lookup table of abbreviations, and it's pretty sizable.  I
want to make sure I don't have any dupes in the table, because it may just
mean I have an error (ST is STATE as well as SAINT?).  So here's my code:

my @city_abbr_list = qw(
    CRNRS   CORNERS
    CTY     CITY
    CY      CITY
...
    W       WEST
    XING    CROSSING
    XRDS    CROSSROADS
);

# Load the hash, and make sure we didn't lose any from dupe keys
my %city_abbr_table = @city_abbr_list;
die "Dupe keys!" if ( (keys %city_abbr_table) != (@city_abbr_list/2) );

So now, my module dies if somehow I have dupe keys in my lookup table, and
I don't have to worry about keeping everything dupe-free by eyeball.

xoxo,
Andy

--
# Andy Lester
%_=split';','.; Perl ;@;st a;m;ker;p;not;o;hac;t;her;y;ju';
print map $_{$_}, split //,
'andy@petdance.com'


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe